diff --git a/.cruft.json b/.cruft.json index fe11e8c..6bfabe6 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,18 +1,18 @@ { "template": "https://github.com/sphinx-notes/template", - "commit": "251643b4d04376494409369c91f29ca047687a5d", + "commit": "a829f105e638f3cba98b799eabef94c0148cd9c0", "checkout": null, "context": { "cookiecutter": { "namespace": "sphinxnotes", - "name": "snippet", - "full_name": "sphinxnotes-snippet", + "name": "picker", + "full_name": "sphinxnotes-picker", "author": "Shengyu Zhang", "description": "Sphinx documentation snippets manager", "version": "1.2", "github_owner": "sphinx-notes", "github_repo": "snippet", - "pypi_name": "sphinxnotes-snippet", + "pypi_name": "sphinxnotes-picker", "pypi_owner": "SilverRainZ", "is_python_project": true, "python_version": "3.12", @@ -20,7 +20,7 @@ "sphinx_version": "7.0", "development_status": "3 - Alpha", "_template": "https://github.com/sphinx-notes/template", - "_commit": "251643b4d04376494409369c91f29ca047687a5d" + "_commit": "a829f105e638f3cba98b799eabef94c0148cd9c0" } }, "directory": null diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 94eda1a..30adcc8 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest environment: name: pypi - url: https://pypi.org/p/sphinxnotes-snippet + url: https://pypi.org/p/sphinxnotes-picker permissions: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing steps: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2c04c00..ebc84fb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,4 +15,4 @@ jobs: - uses: ncipollo/release-action@v1 with: body: | - Changelog: https://sphinx.silverrainz.me/snippet/changelog.html + Changelog: https://sphinx.silverrainz.me/picker/changelog.html diff --git a/Makefile b/Makefile index e3d46d8..9daf528 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ clean: .PHONY: fmt fmt: - ruff format src/ && ruff check --fix src/ + ruff format src/ tests/ && ruff check --fix src/ tests/ .PHONY: test test: @@ -36,7 +36,8 @@ test: # Build distribution package, for "install" or "upload". .PHONY: dist dist: pyproject.toml clean - $(PY) -m build + # Use ``--no-isolation`` to prevent network accessing. + $(PY) -m build --no-isolation # Install distribution package to user directory. # diff --git a/README.rst b/README.rst index 2c1e79d..aa46ae1 100644 --- a/README.rst +++ b/README.rst @@ -1,21 +1,21 @@ .. This file is generated from sphinx-notes/cookiecutter. You need to consider modifying the TEMPLATE or modifying THIS FILE. -=================== -sphinxnotes-snippet -=================== +================== +sphinxnotes-picker +================== -.. |docs| image:: https://img.shields.io/github/deployments/sphinx-notes/snippet/github-pages - :target: https://sphinx.silverrainz.me/snippet +.. |docs| image:: https://img.shields.io/github/deployments/sphinx-notes/picker/github-pages + :target: https://sphinx.silverrainz.me/picker :alt: Documentation Status -.. |license| image:: https://img.shields.io/github/license/sphinx-notes/snippet +.. |license| image:: https://img.shields.io/github/license/sphinx-notes/picker :target: https://github.com/sphinx-notes/snippet/blob/master/LICENSE :alt: Open Source License -.. |pypi| image:: https://img.shields.io/pypi/v/sphinxnotes-snippet.svg - :target: https://pypi.python.org/pypi/sphinxnotes-snippet +.. |pypi| image:: https://img.shields.io/pypi/v/sphinxnotes-picker.svg + :target: https://pypi.python.org/pypi/sphinxnotes-picker :alt: PyPI Package -.. |download| image:: https://img.shields.io/pypi/dm/sphinxnotes-snippet - :target: https://pypistats.org/packages/sphinxnotes-snippet +.. |download| image:: https://img.shields.io/pypi/dm/sphinxnotes-picker + :target: https://pypistats.org/packages/sphinxnotes-picker :alt: PyPI Package Downloads |docs| |license| |pypi| |download| @@ -29,4 +29,4 @@ Sphinx documentation snippets manager. Please refer to Documentation_ for more details. -.. _Documentation: https://sphinx.silverrainz.me/snippet +.. _Documentation: https://sphinx.silverrainz.me/picker diff --git a/docs/_static/custom.css b/docs/_static/custom.css new file mode 100644 index 0000000..814ba33 --- /dev/null +++ b/docs/_static/custom.css @@ -0,0 +1,10 @@ +/* This file is generated from sphinx-notes/cookiecutter. + * DO NOT EDIT. + */ + +/* Missing style for nodes.system_message from Alabaster. */ +.system-message { + background-color: #fda; + padding: 5px; + border: 3px solid red; +} diff --git a/docs/conf.py b/docs/conf.py index f50b6ff..f6b325e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,7 +9,7 @@ # -- Project information ----------------------------------------------------- -project = 'sphinxnotes-snippet' +project = 'sphinxnotes-picker' author = 'Shengyu Zhang' copyright = "2023, " + author @@ -55,12 +55,6 @@ # html_theme = 'furo' -html_theme_options = {} - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] html_theme_options = { "source_repository": "https://github.com/sphinx-notes/snippet/", "source_branch": "master", @@ -69,10 +63,17 @@ # The URL which points to the root of the HTML documentation. # It is used to indicate the location of document like canonical_url -html_baseurl = 'https://sphinx.silverrainz.me/snippet' +html_baseurl = 'https://sphinx.silverrainz.me/picker' html_logo = html_favicon = '_static/sphinx-notes.png' +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +html_css_files = ['custom.css'] + # -- Extensions ------------------------------------------------------------- extensions.append('sphinx.ext.extlinks') @@ -117,7 +118,7 @@ import os import sys sys.path.insert(0, os.path.abspath('../src/sphinxnotes')) -extensions.append('snippet') +extensions.append('picker') # CUSTOM CONFIGURATION diff --git a/docs/index.rst b/docs/index.rst index 2894d52..0a3fc43 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,24 +1,24 @@ .. This file is generated from sphinx-notes/cookiecutter. You need to consider modifying the TEMPLATE or modifying THIS FILE. -=================== -sphinxnotes-snippet -=================== +================== +sphinxnotes-picker +================== -.. |docs| image:: https://img.shields.io/github/deployments/sphinx-notes/snippet/github-pages?label=docs - :target: https://sphinx.silverrainz.me/snippet +.. |docs| image:: https://img.shields.io/github/deployments/sphinx-notes/picker/github-pages?label=docs + :target: https://sphinx.silverrainz.me/picker :alt: Documentation Status -.. |license| image:: https://img.shields.io/github/license/sphinx-notes/snippet +.. |license| image:: https://img.shields.io/github/license/sphinx-notes/picker :target: https://github.com/sphinx-notes/snippet/blob/master/LICENSE :alt: Open Source License -.. |pypi| image:: https://img.shields.io/pypi/v/sphinxnotes-snippet.svg - :target: https://pypistats.org/packages/sphinxnotes-snippet +.. |pypi| image:: https://img.shields.io/pypi/v/sphinxnotes-picker.svg + :target: https://pypistats.org/packages/sphinxnotes-picker :alt: PyPI Package -.. |download| image:: https://img.shields.io/pypi/dm/sphinxnotes-snippet - :target: https://pypi.python.org/pypi/sphinxnotes-snippet +.. |download| image:: https://img.shields.io/pypi/dm/sphinxnotes-picker + :target: https://pypi.python.org/pypi/sphinxnotes-picker :alt: PyPI Package Downloads .. |github| image:: https://img.shields.io/badge/GitHub-181717?style=flat&logo=github&logoColor=white/ - :target: https://github.com/sphinx-notes/snippet + :target: https://github.com/sphinx-notes/picker :alt: GitHub Repository |docs| |license| |pypi| |download| |github| @@ -49,7 +49,7 @@ First, downloading extension from PyPI: .. code-block:: console - $ pip install sphinxnotes-snippet + $ pip install sphinxnotes-picker Then, add the extension name to ``extensions`` configuration item in your @@ -59,7 +59,7 @@ Then, add the extension name to ``extensions`` configuration item in your extensions = [ # … - 'sphinxnotes.snippet', + 'sphinxnotes.picker', # … ] @@ -95,6 +95,7 @@ as part of **The Sphinx Notes Project**. :caption: The Sphinx Notes Project Home + GitHub Blog PyPI diff --git a/pyproject.toml b/pyproject.toml index 2251a7a..273b737 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ # https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#declaring-project-metadata [project] -name = "sphinxnotes-snippet" +name = "sphinxnotes-picker" description = "Sphinx documentation snippets manager" readme = "README.rst" license = "BSD-3-Clause" @@ -38,7 +38,6 @@ classifiers = [ # CUSTOM CLASSIFIERS END ] -# See ``make pyver`` for more details. requires-python = ">=3.12" dependencies = [ "Sphinx >= 7.0", @@ -85,14 +84,15 @@ docs = [ ] [project.urls] -homepage = "https://sphinx.silverrainz.me/snippet" -documentation = "https://sphinx.silverrainz.me/snippet" +homepage = "https://sphinx.silverrainz.me/picker" +documentation = "https://sphinx.silverrainz.me/picker" repository = "https://github.com/sphinx-notes/snippet" -changelog = "https://sphinx.silverrainz.me/snippet/changelog.html" +changelog = "https://sphinx.silverrainz.me/picker/changelog.html" tracker = "https://github.com/sphinx-notes/snippet/issues" [project.scripts] -snippet = "sphinxnotes.snippet.cli:main" +sphinx-picker = "sphinxnotes.picker.cli:main" +sphinxnotes-picker = "sphinxnotes.picker.cli:main" [build-system] requires = ["setuptools>=46.1.0", "setuptools_scm[toml]>=5", "wheel"] @@ -113,4 +113,4 @@ where = ["src"] [tool.setuptools.package-data] # A maps from PACKAGE NAMES to lists of glob patterns, # see also https://setuptools.pypa.io/en/latest/userguide/datafiles.html -"sphinxnotes.snippet.integration" = ["*.*"] +"sphinxnotes.picker.integration" = ["*.*"] diff --git a/src/sphinxnotes/snippet/__init__.py b/src/sphinxnotes/picker/__init__.py similarity index 70% rename from src/sphinxnotes/snippet/__init__.py rename to src/sphinxnotes/picker/__init__.py index 0fd7955..9aaf942 100644 --- a/src/sphinxnotes/snippet/__init__.py +++ b/src/sphinxnotes/picker/__init__.py @@ -1,5 +1,5 @@ """ -sphinxnotes.snippet +sphinxnotes.picker ~~~~~~~~~~~~~~~~~~~ Sphinx extension entrypoint. @@ -11,10 +11,10 @@ def setup(app): # **WARNING**: We don't import these packages globally, because the current - # package (sphinxnotes.snippet) is always resloved when importing - # sphinxnotes.snippet.*. If we import packages here, eventually we will + # package (sphinxnotes.picker) is always resloved when importing + # sphinxnotes.picker.*. If we import packages here, eventually we will # load a lot of packages from the Sphinx. It will seriously **SLOW DOWN** - # the startup time of our CLI tool (sphinxnotes.snippet.cli). + # the startup time of our CLI tool (sphinxnotes.picker.cli). # # .. seealso:: https://github.com/sphinx-notes/snippet/pull/31 from .ext import ( @@ -27,8 +27,8 @@ def setup(app): app.add_builder(SnippetBuilder) - app.add_config_value('snippet_config', {}, '') - app.add_config_value('snippet_patterns', {'*': ['.*']}, '') + app.add_config_value('picker_config', {}, '') + app.add_config_value('picker_patterns', {'*': ['.*']}, '') app.connect('config-inited', on_config_inited) app.connect('env-get-outdated', on_env_get_outdated) diff --git a/src/sphinxnotes/snippet/cache.py b/src/sphinxnotes/picker/cache.py similarity index 99% rename from src/sphinxnotes/snippet/cache.py rename to src/sphinxnotes/picker/cache.py index 78a2efa..cb93aed 100644 --- a/src/sphinxnotes/snippet/cache.py +++ b/src/sphinxnotes/picker/cache.py @@ -1,5 +1,5 @@ """ -sphinxnotes.snippet.cache +sphinxnotes.picker.cache ~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: Copyright 2021 Shengyu Zhang diff --git a/src/sphinxnotes/snippet/cli.py b/src/sphinxnotes/picker/cli.py similarity index 90% rename from src/sphinxnotes/snippet/cli.py rename to src/sphinxnotes/picker/cli.py index a52b17a..b0782b0 100644 --- a/src/sphinxnotes/snippet/cli.py +++ b/src/sphinxnotes/picker/cli.py @@ -1,5 +1,5 @@ """ -sphinxnotes.snippet.cli +sphinxnotes.picker.cli ~~~~~~~~~~~~~~~~~~~~~~~ Command line entrypoint. @@ -28,7 +28,7 @@ from .cache import Cache, IndexID, Index from .table import tablify, COLUMNS -DEFAULT_CONFIG_FILE = path.join(xdg_config_home, 'sphinxnotes', 'snippet', 'conf.py') +DEFAULT_CONFIG_FILE = path.join(xdg_config_home, 'sphinxnotes', 'picker', 'conf.py') class HelpFormatter( @@ -56,14 +56,14 @@ def main(argv: list[str] = sys.argv[1:]): parser = argparse.ArgumentParser( prog=__name__, - description='Sphinx documentation snippets manager', + description='Sphinx documentation pickers', formatter_class=HelpFormatter, epilog=dedent(""" - snippet tags: - d (document) a document - s (section) a section - c (code) a code block - * (any) wildcard for any snippet"""), + filter tags: + d (document) a document + s (section) a section + c (code) a code block + * (any) wildcard for any target"""), ) parser.add_argument( '--version', @@ -82,7 +82,7 @@ def main(argv: list[str] = sys.argv[1:]): 'stat', aliases=['s'], formatter_class=HelpFormatter, - help='show snippets statistic information', + help='show picker statistic information', ) statparser.set_defaults(func=_on_command_stat) @@ -90,7 +90,7 @@ def main(argv: list[str] = sys.argv[1:]): 'list', aliases=['l'], formatter_class=HelpFormatter, - help='list snippet indexes, columns of indexes: %s' % COLUMNS, + help='list picker indexes, columns of indexes: %s' % COLUMNS, ) listparser.add_argument( '--tags', '-t', type=str, default='*', help='list snippets with specified tags' @@ -100,7 +100,7 @@ def main(argv: list[str] = sys.argv[1:]): '-d', type=str, default='**', - help='list snippets whose docname matches shell-style glob pattern', + help='list pickers whose docname matches shell-style glob pattern', ) listparser.add_argument( '--width', @@ -115,13 +115,13 @@ def main(argv: list[str] = sys.argv[1:]): 'get', aliases=['g'], formatter_class=HelpFormatter, - help='get information of snippet by index ID', + help='get information of picker by index ID', ) getparser.add_argument( - '--docname', '-d', action='store_true', help='get docname of snippet' + '--docname', '-d', action='store_true', help='get docname of picker' ) getparser.add_argument( - '--file', '-f', action='store_true', help='get source file path of snippet' + '--file', '-f', action='store_true', help='get source file path of picker' ) getparser.add_argument( '--deps', action='store_true', help='get dependent files of document' @@ -129,29 +129,29 @@ def main(argv: list[str] = sys.argv[1:]): getparser.add_argument( '--line-start', action='store_true', - help='get line number where snippet starts in source file', + help='get line number where picker starts in source file', ) getparser.add_argument( '--line-end', action='store_true', - help='get line number where snippet ends in source file', + help='get line number where picker ends in source file', ) getparser.add_argument( '--text', '-t', action='store_true', - help='get text representation of snippet', + help='get text representation of picker', ) getparser.add_argument( '--src', action='store_true', - help='get source text of snippet', + help='get source text of picker', ) getparser.add_argument( '--url', '-u', action='store_true', - help='get URL of HTML documentation of snippet', + help='get URL of HTML documentation of picker', ) getparser.add_argument('index_id', type=str, nargs='+', help='index ID') getparser.set_defaults(func=_on_command_get) @@ -196,7 +196,7 @@ def main(argv: list[str] = sys.argv[1:]): # NOTE: Importing is slow, do it on demand. from importlib.metadata import version - pkgname = 'sphinxnotes.snippet' + pkgname = 'sphinxnotes.picker' print(pkgname, version(pkgname)) parser.exit() @@ -228,7 +228,7 @@ def _on_command_stat(args: argparse.Namespace): num_projects = len(cache.num_snippets_by_project) num_docs = len(cache.num_snippets_by_docid) num_snippets = sum(cache.num_snippets_by_project.values()) - print(f'snippets are loaded from {cache.dirname}') + print(f'indexes are loaded from {cache.dirname}') print(f'configuration are loaded from {args.config}') print(f'integration files are located at {get_integration_file("")}') print('') diff --git a/src/sphinxnotes/snippet/config/__init__.py b/src/sphinxnotes/picker/config/__init__.py similarity index 97% rename from src/sphinxnotes/snippet/config/__init__.py rename to src/sphinxnotes/picker/config/__init__.py index f97482e..3253390 100644 --- a/src/sphinxnotes/snippet/config/__init__.py +++ b/src/sphinxnotes/picker/config/__init__.py @@ -1,5 +1,5 @@ """ -sphinxnotes.snippet.config +sphinxnotes.picker.config ~~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: Copyright 2021 Shengyu Zhang diff --git a/src/sphinxnotes/snippet/config/default.py b/src/sphinxnotes/picker/config/default.py similarity index 86% rename from src/sphinxnotes/snippet/config/default.py rename to src/sphinxnotes/picker/config/default.py index dd3967d..d321a77 100644 --- a/src/sphinxnotes/snippet/config/default.py +++ b/src/sphinxnotes/picker/config/default.py @@ -1,5 +1,5 @@ """ -sphinxnotes.snippet.config.default +sphinxnotes.picker.config.default ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Snippet default configuration. @@ -19,7 +19,7 @@ (Default: ``"$XDG_CACHE_HOME/sphinxnotes/snippet"``) Path to snippet cache directory. """ -cache_dir = __path.join(__xdg_cache_home, 'sphinxnotes', 'snippet') +cache_dir = __path.join(__xdg_cache_home, 'sphinxnotes', 'picker') """ ``base_urls`` diff --git a/src/sphinxnotes/snippet/ext.py b/src/sphinxnotes/picker/ext.py similarity index 92% rename from src/sphinxnotes/snippet/ext.py rename to src/sphinxnotes/picker/ext.py index 9941038..ce4ff36 100644 --- a/src/sphinxnotes/snippet/ext.py +++ b/src/sphinxnotes/picker/ext.py @@ -1,5 +1,5 @@ """ -sphinxnotes.snippet.ext +sphinxnotes.picker.ext ~~~~~~~~~~~~~~~~~~~~~~~ Sphinx extension implementation, but the entrypoint is located at __init__.py. @@ -81,13 +81,13 @@ def _get_document_allowed_tags(pats: dict[str, list[str]], docname: str) -> str: def on_config_inited(app: Sphinx, appcfg: SphinxConfig) -> None: global cache - cfg = Config(appcfg.snippet_config) + cfg = Config(appcfg.picker_config) cache = Cache(cfg.cache_dir) try: cache.load() except Exception as e: - logger.warning('[snippet] failed to laod cache: %s' % e) + logger.warning('[picker] failed to laod cache: %s' % e) def on_env_get_outdated( @@ -108,13 +108,13 @@ def on_doctree_resolved(app: Sphinx, doctree: nodes.document, docname: str) -> N if not isinstance(doctree, nodes.document): # XXX: It may caused by ablog logger.debug( - '[snippet] node %s is not nodes.document', type(doctree), location=doctree + '[picker] node %s is not nodes.document', type(doctree), location=doctree ) return - allowed_tags = _get_document_allowed_tags(app.config.snippet_patterns, docname) + allowed_tags = _get_document_allowed_tags(app.config.picker_patterns, docname) if not allowed_tags: - logger.debug('[snippet] skip picking: no tag allowed for document %s', docname) + logger.debug('[picker] skip picking: no tag allowed for document %s', docname) return doc = [] @@ -146,7 +146,7 @@ def on_doctree_resolved(app: Sphinx, doctree: nodes.document, docname: str) -> N del cache[cache_key] logger.debug( - '[snippet] picked %s/%s snippets in %s, tags: %s, allowed tags: %s', + '[picker] picked %s/%s pickers in %s, tags: %s, allowed tags: %s', len(doc), len(snippets), docname, diff --git a/src/sphinxnotes/snippet/integration/__init__.py b/src/sphinxnotes/picker/integration/__init__.py similarity index 88% rename from src/sphinxnotes/snippet/integration/__init__.py rename to src/sphinxnotes/picker/integration/__init__.py index 4725262..0350c10 100644 --- a/src/sphinxnotes/snippet/integration/__init__.py +++ b/src/sphinxnotes/picker/integration/__init__.py @@ -1,5 +1,5 @@ """ -sphinxnotes.snippet.integration +sphinxnotes.picker.integration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Dummpy module for including package_data. diff --git a/src/sphinxnotes/snippet/integration/binding.nvim b/src/sphinxnotes/picker/integration/binding.nvim similarity index 68% rename from src/sphinxnotes/snippet/integration/binding.nvim rename to src/sphinxnotes/picker/integration/binding.nvim index 25f0f34..ead2218 100644 --- a/src/sphinxnotes/snippet/integration/binding.nvim +++ b/src/sphinxnotes/picker/integration/binding.nvim @@ -1,4 +1,4 @@ -" NeoVim key binding for sphinxnotes-snippet +" NeoVim key binding for sphinxnotes-picker " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " " :Author: Shengyu Zhang @@ -7,15 +7,15 @@ " " TODO: Support vim? -function! g:SphinxNotesSnippetListAndView() +function! g:SphinxNotesPickerListAndView() function! ListAndView_CB(id) - call g:SphinxNotesSnippetView(a:id) + call g:SphinxNotesPickerView(a:id) endfunction - call g:SphinxNotesSnippetList('"*"', function('ListAndView_CB')) + call g:SphinxNotesPickerList('"*"', function('ListAndView_CB')) endfunction " https://github.com/anhmv/vim-float-window/blob/master/plugin/float-window.vim -function! g:SphinxNotesSnippetView(id) +function! g:SphinxNotesPickerView(id) let height = float2nr((&lines - 2) / 1.5) let row = float2nr((&lines - height) / 2) let width = float2nr(&columns / 1.5) @@ -33,14 +33,14 @@ function! g:SphinxNotesSnippetView(id) let buf = nvim_create_buf(v:false, v:true) " Global for :call - let g:sphinx_notes_snippet_win = nvim_open_win(buf, v:true, opts) + let g:sphinx_notes_picker_win = nvim_open_win(buf, v:true, opts) " The content is always reStructuredText for now set filetype=rst " Press enter to return - nmap :call nvim_win_close(g:sphinx_notes_snippet_win, v:true) + nmap :call nvim_win_close(g:sphinx_notes_picker_win, v:true) - let cmd = [s:snippet, 'get', '--src', a:id] + let cmd = [s:picker, 'get', '--src', a:id] call append(line('$'), ['.. hint:: Press to return']) execute '$read !' . '..' execute '$read !' . join(cmd, ' ') @@ -48,7 +48,7 @@ function! g:SphinxNotesSnippetView(id) call append(line('$'), ['.. hint:: Press to return']) endfunction -nmap v :call g:SphinxNotesSnippetListAndView() +nmap v :call g:SphinxNotesPickerListAndView() " vim: set shiftwidth=2: " vim: set ft=vim: diff --git a/src/sphinxnotes/picker/integration/binding.sh b/src/sphinxnotes/picker/integration/binding.sh new file mode 100644 index 0000000..e245050 --- /dev/null +++ b/src/sphinxnotes/picker/integration/binding.sh @@ -0,0 +1,55 @@ +# Bash Shell key binding for sphinxnotes-picker +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# :Author: Shengyu Zhang +# :Date: 2021-08-14 +# :Version: 20240828 + +function picker_view() { + selection=$(picker_list) + [ -z "$selection" ] && return + + # Make sure we have $PAGER + if [ -z "$PAGER" ]; then + if [ ! -z "$(where less)" ]; then + PAGER='less' + else + PAGER='cat' + fi + fi + + echo "$PICKER get --src $selection | $PAGER" +} + +function picker_edit() { + selection=$(picker_list --tags ds) + [ -z "$selection" ] && return + + echo "vim +\$($PICKER get --line-start $selection) \$($PICKER get --file $selection)" +} + +function picker_url() { + selection=$(picker_list --tags ds) + [ -z "$selection" ] && return + + echo "xdg-open \$($PICKER get --url $selection)" +} + +function picker_sh_bind_wrapper() { + cmd=$($1) + if [ ! -z "$cmd" ]; then + eval "$cmd" + fi +} + +function picker_sh_do_bind() { + bind -x '"\C-kv": picker_sh_bind_wrapper picker_view' + bind -x '"\C-ke": picker_sh_bind_wrapper picker_edit' + bind -x '"\C-ku": picker_sh_bind_wrapper picker_url' +} + +# Bind key if bind command exists +# (the script may sourced by Zsh) +command -v bind 2>&1 1>/dev/null && picker_sh_do_bind + +# vim: set shiftwidth=2: diff --git a/src/sphinxnotes/picker/integration/binding.vim b/src/sphinxnotes/picker/integration/binding.vim new file mode 100644 index 0000000..ada7edc --- /dev/null +++ b/src/sphinxnotes/picker/integration/binding.vim @@ -0,0 +1,45 @@ +" Vim key binding for sphinxnotes-picker +" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +" +" :Author: Shengyu Zhang +" :Date: 2021-04-12 +" :Version: 20211114 +" + +function g:SphinxNotesPickerEdit(id) + let file = g:SphinxNotesPickerGet(a:id, 'file')[0] + let line = g:SphinxNotesPickerGet(a:id, 'line-start')[0] + if &modified + execute 'vsplit ' . file + else + execute 'edit ' . file + endif + execute line +endfunction + +function g:SphinxNotesPickerListAndEdit() + function! ListAndEdit_CB(id) + call g:SphinxNotesPickerEdit(a:id) + endfunction + call g:SphinxNotesPickerList('ds', function('ListAndEdit_CB')) +endfunction + +function g:SphinxNotesPickerUrl(id) + let url_list = g:SphinxNotesPickerGet(a:id, 'url') + for url in url_list + echo system('xdg-open ' . shellescape(url)) + endfor +endfunction + +function g:SphinxNotesPickerListAndUrl() + function! ListAndUrl_CB(id) + call g:SphinxNotesPickerUrl(a:id) + endfunction + call g:SphinxNotesPickerList('ds', function('ListAndUrl_CB')) +endfunction + +nmap e :call g:SphinxNotesPickerListAndEdit() +nmap u :call g:SphinxNotesPickerListAndUrl() +nmap i :call g:SphinxNotesPickerListAndInput() + +" vim: set shiftwidth=2: diff --git a/src/sphinxnotes/picker/integration/binding.zsh b/src/sphinxnotes/picker/integration/binding.zsh new file mode 100644 index 0000000..63fa659 --- /dev/null +++ b/src/sphinxnotes/picker/integration/binding.zsh @@ -0,0 +1,35 @@ +# Z Shell key binding for sphinxnotes-picker +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# :Author: Shengyu Zhang +# :Date: 2021-04-12 +# :Version: 20211114 + +# $1: One of picker_* functions +function picker_z_bind_wrapper() { + picker_sh_bind_wrapper $1 + zle redisplay +} + +function picker_z_view() { + picker_z_bind_wrapper picker_view +} + +function picker_z_edit() { + picker_z_bind_wrapper picker_edit +} + +function picker_z_url() { + picker_z_bind_wrapper picker_url +} + +# Define widgets +zle -N picker_z_view +zle -N picker_z_edit +zle -N picker_z_url + +bindkey '^kv' picker_z_view +bindkey '^ke' picker_z_edit +bindkey '^ku' picker_z_url + +# vim: set shiftwidth=2: diff --git a/src/sphinxnotes/snippet/integration/plugin.sh b/src/sphinxnotes/picker/integration/plugin.sh similarity index 55% rename from src/sphinxnotes/snippet/integration/plugin.sh rename to src/sphinxnotes/picker/integration/plugin.sh index 3d24a91..9777f37 100644 --- a/src/sphinxnotes/snippet/integration/plugin.sh +++ b/src/sphinxnotes/picker/integration/plugin.sh @@ -1,17 +1,17 @@ -# Bash Shell integration for sphinxnotes-snippet +# Bash Shell integration for sphinxnotes-picker # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # :Author: Shengyu Zhang # :Date: 2021-03-20 # :Version: 20240828 -# Make sure we have $SNIPPET -[ -z "$SNIPPET"] && SNIPPET='snippet' +# Make sure we have $PICKER +[ -z "$PICKER"] && PICKER='sphinxnotes-picker' -# Arguments: $*: Extra opts of ``snippet list`` -# Returns: snippet_id -function snippet_list() { - $SNIPPET list --width $(($(tput cols) - 2)) "$@" | \ +# Arguments: $*: Extra opts of ``picker list`` +# Returns: picker_id +function picker_list() { + $PICKER list --width $(($(tput cols) - 2)) "$@" | \ fzf --with-nth 2.. \ --no-hscroll \ --header-lines 1 \ diff --git a/src/sphinxnotes/snippet/integration/plugin.vim b/src/sphinxnotes/picker/integration/plugin.vim similarity index 77% rename from src/sphinxnotes/snippet/integration/plugin.vim rename to src/sphinxnotes/picker/integration/plugin.vim index 3cf01c5..106aad8 100644 --- a/src/sphinxnotes/snippet/integration/plugin.vim +++ b/src/sphinxnotes/picker/integration/plugin.vim @@ -1,4 +1,4 @@ -" Vim integration for sphinxnotes-snippet +" Vim integration for sphinxnotes-picker " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " " :Author: Shengyu Zhang @@ -7,13 +7,13 @@ " " NOTE: junegunn/fzf.vim is required -let s:snippet = 'snippet' +let s:picker = 'sphinxnotes-picker' let s:width = 0.9 let s:height = 0.6 " Use fzf to list all snippets, callback with argument id. -function g:SphinxNotesSnippetList(tags, callback) - let cmd = [s:snippet, 'list', +function g:SphinxNotesPickerList(tags, callback) + let cmd = [s:picker, 'list', \ '--tags', a:tags, \ '--width', float2nr(&columns * s:width) - 2, \ ] @@ -36,14 +36,14 @@ function g:SphinxNotesSnippetList(tags, callback) endfunction " Return the attribute value of specific snippet. -function g:SphinxNotesSnippetGet(id, attr) - let cmd = [s:snippet, 'get', a:id, '--' . a:attr] +function g:SphinxNotesPickerGet(id, attr) + let cmd = [s:picker, 'get', a:id, '--' . a:attr] return systemlist(join(cmd, ' ')) endfunction " Use fzf to list all attr of specific snippet, " callback with arguments (attr_name, attr_value). -function g:SphinxNotesSnippetListSnippetAttrs(id, callback) +function g:SphinxNotesPickerListPickerAttrs(id, callback) " Display attr -> Identify attr (also used as CLI option) let attrs = { \ 'Source': 'src', @@ -59,17 +59,17 @@ function g:SphinxNotesSnippetListSnippetAttrs(id, callback) call add(table, attrs[name] . delim . name) endfor - function! ListSnippetAttrs_CB(selection) closure + function! ListPickerAttrs_CB(selection) closure let opt = split(a:selection, ' ')[0] - let val = g:SphinxNotesSnippetGet(a:id, opt) + let val = g:SphinxNotesPickerGet(a:id, opt) call a:callback(opt, val) " finally call user's cb endfunction - let preview_cmd = [s:snippet, 'get', a:id, '--$(echo {} | cut -d " " -f1)'] + let preview_cmd = [s:picker, 'get', a:id, '--$(echo {} | cut -d " " -f1)'] let info_cmd = ['echo', 'Index ID:', a:id] call fzf#run({ \ 'source': table, - \ 'sink': function('ListSnippetAttrs_CB'), + \ 'sink': function('ListPickerAttrs_CB'), \ 'options': [ \ '--header-lines', '1', \ '--with-nth', '2..', @@ -81,7 +81,7 @@ function g:SphinxNotesSnippetListSnippetAttrs(id, callback) \ }) endfunction -function g:SphinxNotesSnippetInput(id) +function g:SphinxNotesPickerInput(id) function! Input_CB(attr, val) " TODO: became g:func. if a:attr == 'docname' " Create doc reference. @@ -95,15 +95,15 @@ function g:SphinxNotesSnippetInput(id) execute 'normal! i' . content endfunction - call g:SphinxNotesSnippetListSnippetAttrs(a:id, function('Input_CB')) + call g:SphinxNotesPickerListPickerAttrs(a:id, function('Input_CB')) endfunction -function g:SphinxNotesSnippetListAndInput() +function g:SphinxNotesPickerListAndInput() function! ListAndInput_CB(id) - call g:SphinxNotesSnippetInput(a:id) + call g:SphinxNotesPickerInput(a:id) endfunction - call g:SphinxNotesSnippetList('"*"', function('ListAndInput_CB')) + call g:SphinxNotesPickerList('"*"', function('ListAndInput_CB')) endfunction " vim: set shiftwidth=2: diff --git a/src/sphinxnotes/snippet/keyword.py b/src/sphinxnotes/picker/keyword.py similarity index 99% rename from src/sphinxnotes/snippet/keyword.py rename to src/sphinxnotes/picker/keyword.py index ef262b6..5019fa7 100644 --- a/src/sphinxnotes/snippet/keyword.py +++ b/src/sphinxnotes/picker/keyword.py @@ -1,5 +1,5 @@ """ -sphinxnotes.snippet.keyword +sphinxnotes.picker.keyword ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Helper functions for keywords extraction. diff --git a/src/sphinxnotes/snippet/meta.py b/src/sphinxnotes/picker/meta.py similarity index 91% rename from src/sphinxnotes/snippet/meta.py rename to src/sphinxnotes/picker/meta.py index 27cdb4b..05d0066 100644 --- a/src/sphinxnotes/snippet/meta.py +++ b/src/sphinxnotes/picker/meta.py @@ -12,12 +12,12 @@ from sphinx.util.typing import ExtensionMetadata -__project__ = 'sphinxnotes-snippet' +__project__ = 'sphinxnotes-picker' __author__ = 'Shengyu Zhang' __desc__ = 'Sphinx documentation snippets manager' try: - __version__ = metadata.version('sphinxnotes-snippet') + __version__ = metadata.version('sphinxnotes-picker') except metadata.PackageNotFoundError: __version__ = 'unknown' diff --git a/src/sphinxnotes/snippet/picker.py b/src/sphinxnotes/picker/picker.py similarity index 99% rename from src/sphinxnotes/snippet/picker.py rename to src/sphinxnotes/picker/picker.py index ea1b4cf..89e529c 100644 --- a/src/sphinxnotes/snippet/picker.py +++ b/src/sphinxnotes/picker/picker.py @@ -1,5 +1,5 @@ """ -sphinxnotes.snippet.picker +sphinxnotes.picker.picker ~~~~~~~~~~~~~~~~~~~~~~~~~~ Snippet picker implementations. diff --git a/src/sphinxnotes/snippet/py.typed b/src/sphinxnotes/picker/py.typed similarity index 100% rename from src/sphinxnotes/snippet/py.typed rename to src/sphinxnotes/picker/py.typed diff --git a/src/sphinxnotes/snippet/snippets.py b/src/sphinxnotes/picker/snippets.py similarity index 99% rename from src/sphinxnotes/snippet/snippets.py rename to src/sphinxnotes/picker/snippets.py index f14661a..cba60c2 100644 --- a/src/sphinxnotes/snippet/snippets.py +++ b/src/sphinxnotes/picker/snippets.py @@ -1,5 +1,5 @@ """ -sphinxnotes.snippet.snippets +sphinxnotes.picker.snippets ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Definitions of various snippets. diff --git a/src/sphinxnotes/snippet/table.py b/src/sphinxnotes/picker/table.py similarity index 98% rename from src/sphinxnotes/snippet/table.py rename to src/sphinxnotes/picker/table.py index 8138573..4bbc0cf 100644 --- a/src/sphinxnotes/snippet/table.py +++ b/src/sphinxnotes/picker/table.py @@ -1,5 +1,5 @@ """ -sphinxnotes.snippet.table +sphinxnotes.picker.table ~~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: Copyright 2021 Shengyu Zhang diff --git a/src/sphinxnotes/snippet/utils/__init__.py b/src/sphinxnotes/picker/utils/__init__.py similarity index 100% rename from src/sphinxnotes/snippet/utils/__init__.py rename to src/sphinxnotes/picker/utils/__init__.py diff --git a/src/sphinxnotes/snippet/utils/ellipsis.py b/src/sphinxnotes/picker/utils/ellipsis.py similarity index 100% rename from src/sphinxnotes/snippet/utils/ellipsis.py rename to src/sphinxnotes/picker/utils/ellipsis.py diff --git a/src/sphinxnotes/snippet/utils/pdict.py b/src/sphinxnotes/picker/utils/pdict.py similarity index 100% rename from src/sphinxnotes/snippet/utils/pdict.py rename to src/sphinxnotes/picker/utils/pdict.py diff --git a/src/sphinxnotes/snippet/utils/titlepath.py b/src/sphinxnotes/picker/utils/titlepath.py similarity index 100% rename from src/sphinxnotes/snippet/utils/titlepath.py rename to src/sphinxnotes/picker/utils/titlepath.py diff --git a/src/sphinxnotes/snippet/integration/binding.sh b/src/sphinxnotes/snippet/integration/binding.sh deleted file mode 100644 index f831d58..0000000 --- a/src/sphinxnotes/snippet/integration/binding.sh +++ /dev/null @@ -1,55 +0,0 @@ -# Bash Shell key binding for sphinxnotes-snippet -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# :Author: Shengyu Zhang -# :Date: 2021-08-14 -# :Version: 20240828 - -function snippet_view() { - selection=$(snippet_list) - [ -z "$selection" ] && return - - # Make sure we have $PAGER - if [ -z "$PAGER" ]; then - if [ ! -z "$(where less)" ]; then - PAGER='less' - else - PAGER='cat' - fi - fi - - echo "$SNIPPET get --src $selection | $PAGER" -} - -function snippet_edit() { - selection=$(snippet_list --tags ds) - [ -z "$selection" ] && return - - echo "vim +\$($SNIPPET get --line-start $selection) \$($SNIPPET get --file $selection)" -} - -function snippet_url() { - selection=$(snippet_list --tags ds) - [ -z "$selection" ] && return - - echo "xdg-open \$($SNIPPET get --url $selection)" -} - -function snippet_sh_bind_wrapper() { - cmd=$($1) - if [ ! -z "$cmd" ]; then - eval "$cmd" - fi -} - -function snippet_sh_do_bind() { - bind -x '"\C-kv": snippet_sh_bind_wrapper snippet_view' - bind -x '"\C-ke": snippet_sh_bind_wrapper snippet_edit' - bind -x '"\C-ku": snippet_sh_bind_wrapper snippet_url' -} - -# Bind key if bind command exists -# (the script may sourced by Zsh) -command -v bind 2>&1 1>/dev/null && snippet_sh_do_bind - -# vim: set shiftwidth=2: diff --git a/src/sphinxnotes/snippet/integration/binding.vim b/src/sphinxnotes/snippet/integration/binding.vim deleted file mode 100644 index 6225080..0000000 --- a/src/sphinxnotes/snippet/integration/binding.vim +++ /dev/null @@ -1,45 +0,0 @@ -" Vim key binding for sphinxnotes-snippet -" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -" -" :Author: Shengyu Zhang -" :Date: 2021-04-12 -" :Version: 20211114 -" - -function g:SphinxNotesSnippetEdit(id) - let file = g:SphinxNotesSnippetGet(a:id, 'file')[0] - let line = g:SphinxNotesSnippetGet(a:id, 'line-start')[0] - if &modified - execute 'vsplit ' . file - else - execute 'edit ' . file - endif - execute line -endfunction - -function g:SphinxNotesSnippetListAndEdit() - function! ListAndEdit_CB(id) - call g:SphinxNotesSnippetEdit(a:id) - endfunction - call g:SphinxNotesSnippetList('ds', function('ListAndEdit_CB')) -endfunction - -function g:SphinxNotesSnippetUrl(id) - let url_list = g:SphinxNotesSnippetGet(a:id, 'url') - for url in url_list - echo system('xdg-open ' . shellescape(url)) - endfor -endfunction - -function g:SphinxNotesSnippetListAndUrl() - function! ListAndUrl_CB(id) - call g:SphinxNotesSnippetUrl(a:id) - endfunction - call g:SphinxNotesSnippetList('ds', function('ListAndUrl_CB')) -endfunction - -nmap e :call g:SphinxNotesSnippetListAndEdit() -nmap u :call g:SphinxNotesSnippetListAndUrl() -nmap i :call g:SphinxNotesSnippetListAndInput() - -" vim: set shiftwidth=2: diff --git a/src/sphinxnotes/snippet/integration/binding.zsh b/src/sphinxnotes/snippet/integration/binding.zsh deleted file mode 100644 index a53bd28..0000000 --- a/src/sphinxnotes/snippet/integration/binding.zsh +++ /dev/null @@ -1,35 +0,0 @@ -# Z Shell key binding for sphinxnotes-snippet -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# :Author: Shengyu Zhang -# :Date: 2021-04-12 -# :Version: 20211114 - -# $1: One of snippet_* functions -function snippet_z_bind_wrapper() { - snippet_sh_bind_wrapper $1 - zle redisplay -} - -function snippet_z_view() { - snippet_z_bind_wrapper snippet_view -} - -function snippet_z_edit() { - snippet_z_bind_wrapper snippet_edit -} - -function snippet_z_url() { - snippet_z_bind_wrapper snippet_url -} - -# Define widgets -zle -N snippet_z_view -zle -N snippet_z_edit -zle -N snippet_z_url - -bindkey '^kv' snippet_z_view -bindkey '^ke' snippet_z_edit -bindkey '^ku' snippet_z_url - -# vim: set shiftwidth=2: diff --git a/utils/conf.py b/utils/conf.py index 92103db..a7ac59a 100644 --- a/utils/conf.py +++ b/utils/conf.py @@ -2,9 +2,9 @@ from os import path -cache_dir = '/tmp/sphinxnotes-snippet' +cache_dir = '/tmp/sphinxnotes-picker' base_urls = { - 'sphinxnotes-snippet': 'file://' + 'sphinxnotes-picker': 'file://' + path.join(path.dirname(path.dirname(path.realpath(__file__))), 'doc/_build/html'), }