From 659aa898e994cc7646a13fa1b94a1279a1faaacd Mon Sep 17 00:00:00 2001 From: Florian Adamsky Date: Sat, 5 Dec 2020 14:36:38 +0100 Subject: [PATCH 1/3] [texdoc] add texdoc plugin --- texdoc/__init__.py | 68 +++++++++++ texdoc/texdoc-logo.svg | 259 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 327 insertions(+) create mode 100644 texdoc/__init__.py create mode 100644 texdoc/texdoc-logo.svg diff --git a/texdoc/__init__.py b/texdoc/__init__.py new file mode 100644 index 00000000..dc9ae5ec --- /dev/null +++ b/texdoc/__init__.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- + +"""texdoc extension + +This is an extension to search for LaTeX documentation. + +Synopsis: """ + +import os +import re +import subprocess + +from shutil import which +from albertv0 import * + +__iid__ = "PythonInterface/v0.3" +__prettyname__ = "TeXdoc" +__version__ = "1.0" +__trigger__ = "td" +__author__ = "Florian Adamsky" +__dependencies__ = ["texdoc"] + +iconPath = os.path.dirname(__file__)+"/texdoc-logo.svg" +texdoc_cmd = ["texdoc", "-I", "-q", "-s", "-M"] + +if which("texdoc") is None: + raise Exception("'texdoc' is not in $PATH.") + +def handleQuery(query): + if not query.isTriggered: + return + + query.disableSort() + + stripped_query = query.string.strip() + + if stripped_query: + process = subprocess.run(["texdoc", "-I", "-q", "-s", "-M", stripped_query], + stdout=subprocess.PIPE) + texdoc_output = process.stdout.decode("utf-8") + + results = [] + for line in texdoc_output.split("\n"): + + match = re.search('\t(/.*/)([\w\.-]+)\t\t', line, re.IGNORECASE) + if match: + directory = match.group(1).strip() + filename = match.group(2).strip() + full_path = directory.join(['/', filename]) + + results.append(Item(id = __prettyname__, + icon = iconPath, + text = filename, + subtext = directory, + completion = full_path, + actions = [ + ProcAction(text='This action opens the documentation.', + commandline=['xdg-open', full_path]) + ])) + + + return results + else: + return Item(id=__prettyname__, + icon=iconPath, + text=__prettyname__, + subtext="Enter a query to search with texdoc", + completion=query.rawString) diff --git a/texdoc/texdoc-logo.svg b/texdoc/texdoc-logo.svg new file mode 100644 index 00000000..47784fc3 --- /dev/null +++ b/texdoc/texdoc-logo.svg @@ -0,0 +1,259 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From f3b3566727fbc5875cf430fee6de1cb318343d69 Mon Sep 17 00:00:00 2001 From: Florian Adamsky Date: Sun, 6 Dec 2020 08:24:59 +0100 Subject: [PATCH 2/3] [texdoc] integrate comments from the code review --- texdoc/__init__.py | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/texdoc/__init__.py b/texdoc/__init__.py index dc9ae5ec..35c22400 100644 --- a/texdoc/__init__.py +++ b/texdoc/__init__.py @@ -6,22 +6,22 @@ Synopsis: """ -import os import re import subprocess -from shutil import which +from shutil import which +from pathlib import Path from albertv0 import * -__iid__ = "PythonInterface/v0.3" -__prettyname__ = "TeXdoc" -__version__ = "1.0" -__trigger__ = "td" -__author__ = "Florian Adamsky" -__dependencies__ = ["texdoc"] +__iid__ = 'PythonInterface/v0.3' +__prettyname__ = 'TeXdoc' +__version__ = '1.0' +__trigger__ = 'td' +__author__ = 'Florian Adamsky' +__dependencies__ = ['texdoc'] -iconPath = os.path.dirname(__file__)+"/texdoc-logo.svg" -texdoc_cmd = ["texdoc", "-I", "-q", "-s", "-M"] +iconPath = Path(__file__).parent / 'texdoc-logo.svg' +texdoc_cmd = ['texdoc', '-I', '-q', '-s', '-M'] if which("texdoc") is None: raise Exception("'texdoc' is not in $PATH.") @@ -35,9 +35,9 @@ def handleQuery(query): stripped_query = query.string.strip() if stripped_query: - process = subprocess.run(["texdoc", "-I", "-q", "-s", "-M", stripped_query], + process = subprocess.run(texdoc_cmd + [stripped_query], stdout=subprocess.PIPE) - texdoc_output = process.stdout.decode("utf-8") + texdoc_output = process.stdout.decode('utf-8') results = [] for line in texdoc_output.split("\n"): @@ -49,20 +49,19 @@ def handleQuery(query): full_path = directory.join(['/', filename]) results.append(Item(id = __prettyname__, - icon = iconPath, + icon = str(iconPath), text = filename, subtext = directory, completion = full_path, actions = [ - ProcAction(text='This action opens the documentation.', + ProcAction(text = 'This action opens the documentation.', commandline=['xdg-open', full_path]) ])) - return results else: - return Item(id=__prettyname__, - icon=iconPath, - text=__prettyname__, - subtext="Enter a query to search with texdoc", - completion=query.rawString) + return Item(id = __prettyname__, + icon = str(iconPath), + text = __prettyname__, + subtext = 'Enter a query to search with texdoc', + completion = query.rawString) From a47948e69ad72b7f049c4d308297b599685c8f5d Mon Sep 17 00:00:00 2001 From: Florian Adamsky Date: Wed, 9 Dec 2020 07:51:36 +0100 Subject: [PATCH 3/3] add github username for easy mentions Co-authored-by: Dave Shoreman --- texdoc/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/texdoc/__init__.py b/texdoc/__init__.py index 35c22400..990390e6 100644 --- a/texdoc/__init__.py +++ b/texdoc/__init__.py @@ -17,7 +17,7 @@ __prettyname__ = 'TeXdoc' __version__ = '1.0' __trigger__ = 'td' -__author__ = 'Florian Adamsky' +__author__ = 'Florian Adamsky (@cit)' __dependencies__ = ['texdoc'] iconPath = Path(__file__).parent / 'texdoc-logo.svg'