summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Gallo <aamsgallo@gmail.com>2019-01-09 23:02:53 +0100
committerAlejandro Gallo <aamsgallo@gmail.com>2019-01-09 23:02:53 +0100
commit676a4b02bf7b830a972416c03c0734d0aeab509d (patch)
treea7572611c6f7cc353de32e2e5d6deb634cc0845a
parentec8073e09a01fcc18c8255dc511fd484b0fb1a7e (diff)
parenta6fec3752d53897ab9af22b194011a492eac1876 (diff)
Merge branch 'papis-gui-erase'
-rw-r--r--doc/source/configuration.rst1
-rw-r--r--papis/api.py15
-rw-r--r--papis/config.py27
-rw-r--r--papis/gui/__init__.py105
-rw-r--r--papis/gui/dmenu.py49
-rw-r--r--papis/gui/vim/__init__.py2
-rw-r--r--papis/gui/vim/main.py81
-rw-r--r--papis/gui/vim/main.vim143
-rw-r--r--papis/gui/vim/pick.vim14
-rw-r--r--setup.py5
-rw-r--r--tests/commands/test_config.py23
11 files changed, 20 insertions, 445 deletions
diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst
index 7b2f8300..cabdfe0b 100644
--- a/doc/source/configuration.rst
+++ b/doc/source/configuration.rst
@@ -114,6 +114,5 @@ Default settings
----------------
.. automodule:: papis.config
-.. automodule:: papis.gui
diff --git a/papis/api.py b/papis/api.py
index b5f9c617..72c40d10 100644
--- a/papis/api.py
+++ b/papis/api.py
@@ -136,19 +136,14 @@ def pick(options: list, pick_config={}):
# Leave this import here
import papis.config
logger.debug("Parsing picktool")
- picker = papis.config.get("picktool")
- if picker == "dmenu":
- import papis.gui.dmenu
- logger.debug("Using dmenu picker")
- return papis.gui.dmenu.pick(options, **pick_config)
- elif picker == "vim":
- import papis.gui.vim
- logger.debug("Using vim picker")
- return papis.gui.vim.pick(options, **pick_config)
- elif picker == "papis.pick":
+ external_picker = papis.config.get_external_picker()
+ picker = external_picker or papis.config.get("picktool")
+ if picker == "papis.pick":
import papis.pick
logger.debug("Using papis.pick picker")
return papis.pick.pick(options, **pick_config)
+ elif papis.config.get_external_picker() is not None:
+ return papis.config.get_external_picker()(options, **pick_config)
else:
raise Exception("I don't know how to use the picker '%s'" % picker)
diff --git a/papis/config.py b/papis/config.py
index 1b9ede90..db8c55f3 100644
--- a/papis/config.py
+++ b/papis/config.py
@@ -165,8 +165,6 @@ Tools options
Possible options are:
- papis.pick
- - vim
- - dmenu
.. papis-config:: editor
:default: $EDITOR
@@ -176,13 +174,6 @@ Tools options
not set then it will default to the ``$VISUAL`` environment variable.
Otherwise the default editor in your system will be used.
-.. papis-config:: xeditor
-
- Sometimes papis might use an editor that uses a windowing system
- (GUI Editor), you can set this to your preferred gui based editor, e.g.
- ``gedit``, ``xemacs``, ``gvim`` to name a few.
-
-
.. papis-config:: file-browser
File browser to be used when opening a directory, it defaults to the
@@ -503,6 +494,7 @@ import configparser
import papis.exceptions
+_EXTERNAL_PICKER = None #: Picker to set externally
_CONFIGURATION = None #: Global configuration object variable.
_DEFAULT_SETTINGS = None #: Default settings for the whole papis.
_OVERRIDE_VARS = {
@@ -538,7 +530,6 @@ general_settings = {
"editor": os.environ.get('EDITOR')
or os.environ.get('VISUAL')
or get_default_opener(),
- "xeditor": get_default_opener(),
"notes-name": "notes.tex",
"use-cache": True,
"cache-dir": None,
@@ -641,11 +632,8 @@ def get_default_settings(section="", key=""):
'mv'
>>> get_default_settings(key='mvtool', section='settings')
'mv'
- >>> get_default_settings(key='help-key', section='vim-gui')
- 'h'
"""
global _DEFAULT_SETTINGS
- import papis.gui
# We use an OrderedDict so that the first entry will always be the general
# settings, also good for automatic documentation
from collections import OrderedDict
@@ -654,9 +642,6 @@ def get_default_settings(section="", key=""):
_DEFAULT_SETTINGS.update({
get_general_settings_name(): general_settings,
})
- _DEFAULT_SETTINGS.update(
- papis.gui.get_default_settings()
- )
if not section and not key:
return _DEFAULT_SETTINGS
elif not section:
@@ -784,6 +769,16 @@ def set_config_file(filepath):
_OVERRIDE_VARS["file"] = filepath
+def set_external_picker(picker):
+ global _EXTERNAL_PICKER
+ _EXTERNAL_PICKER = picker
+
+
+def get_external_picker():
+ global _EXTERNAL_PICKER
+ return _EXTERNAL_PICKER
+
+
def get_scripts_folder():
"""Get folder where the scripts are stored,
e.g. /home/user/.papis/scripts
diff --git a/papis/gui/__init__.py b/papis/gui/__init__.py
deleted file mode 100644
index dc55d496..00000000
--- a/papis/gui/__init__.py
+++ /dev/null
@@ -1,105 +0,0 @@
-"""
-Vim gui
-*******
-
-.. papis-config:: help-key
- :section: vim-gui
-
-.. papis-config:: open-key
- :section: vim-gui
-
-.. papis-config:: edit-key
- :section: vim-gui
-
-.. papis-config:: search-key
- :section: vim-gui
-
-.. papis-config:: delete-key
- :section: vim-gui
-
-.. papis-config:: open-dir-key
- :section: vim-gui
-
-.. papis-config:: next-search-key
- :section: vim-gui
-
-.. papis-config:: prev-search-key
- :section: vim-gui
-
-.. papis-config:: header-format
- :section: vim-gui
-
-dmenu gui
-*********
-
-See `dmenu <https://tools.suckless.org/dmenu/>`_ and the python wrapper
-`here <http://dmenu.readthedocs.io/en/latest/>`_ for more information.
-You will need to install the latter to make use of this function,
-
-::
-
- pip3 install dmenu
-
-
-.. papis-config:: lines
- :section: dmenu-gui
-
-.. papis-config:: case_insensitive
- :section: dmenu-gui
-
-.. papis-config:: bottom
- :section: dmenu-gui
-
-.. papis-config:: font
- :section: dmenu-gui
-
-.. papis-config:: background
- :section: dmenu-gui
-
-.. papis-config:: foreground
- :section: dmenu-gui
-
-.. papis-config:: background_selected
- :section: dmenu-gui
-
-.. papis-config:: foreground_selected
- :section: dmenu-gui
-
-.. papis-config:: header-format
- :section: dmenu-gui
-
- This is not set per default, and it will default to
- the general header-format if not set.
-
-"""
-
-
-def get_default_settings():
- return {
- "vim-gui": {
- "help-key": "h",
- "open-key": "o",
- "edit-key": "e",
- "search-key": "/",
- "delete-key": "dd",
- "open-dir-key": "<S-o>",
- "next-search-key": "n",
- "prev-search-key": "N",
- "header-format":
- "Title : {doc[title]}\n"
- "Author: {doc[author]}\n"
- "Year : {doc[year]}\n"
- "-------\n",
- },
- "dmenu-gui": {
- "lines": 20,
- "case_insensitive": True,
- "bottom": True,
- "font": 'monospace-14',
- "background": '#000000',
- "foreground": '#55ff55',
- "background_selected": '#005500',
- "foreground_selected": '#f0f0f0',
- "header-format": None,
- },
- }
diff --git a/papis/gui/dmenu.py b/papis/gui/dmenu.py
deleted file mode 100644
index e0d94e49..00000000
--- a/papis/gui/dmenu.py
+++ /dev/null
@@ -1,49 +0,0 @@
-import sys
-
-try:
- import dmenu
-except:
- print('You don\'t have dmenu for python, try pip3 install dmenu')
- sys.exit(1)
-
-import papis.api
-import papis.utils
-import functools
-
-
-_dmenu_pick = functools.partial(
- dmenu.show,
- case_insensitive=papis.config.getboolean(
- 'case_insensitive', section="dmenu-gui"
- ),
- lines=papis.config.getint('lines', section='dmenu-gui'),
- bottom=papis.config.getboolean('bottom', section='dmenu-gui'),
- font=papis.config.get('font', section='dmenu-gui'),
- background=papis.config.get('background', section='dmenu-gui'),
- foreground=papis.config.get('foreground', section='dmenu-gui'),
- background_selected=papis.config.get(
- 'background_selected', section='dmenu-gui'
- ),
- foreground_selected=papis.config.get(
- 'foreground_selected', section='dmenu-gui'
- )
-)
-
-
-def pick(options, header_filter=None, body_filter=None, match_filter=None):
- if header_filter is None:
- fmt = papis.config.get('header-format', section='dmenu-gui')
- if fmt is None:
- fmt = papis.config.get('header-format')
-
- def header_filter(x):
- return papis.utils.format_doc(fmt, x)
- if len(options) == 1:
- index = 0
- else:
- headers = [header_filter(o) for o in options]
- header = _dmenu_pick(headers)
- if not header:
- return None
- index = headers.index(header)
- return options[index]
diff --git a/papis/gui/vim/__init__.py b/papis/gui/vim/__init__.py
deleted file mode 100644
index a2c95a8b..00000000
--- a/papis/gui/vim/__init__.py
+++ /dev/null
@@ -1,2 +0,0 @@
-from papis.gui.vim.main import Gui
-from papis.gui.vim.main import pick
diff --git a/papis/gui/vim/main.py b/papis/gui/vim/main.py
deleted file mode 100644
index 21a70c6e..00000000
--- a/papis/gui/vim/main.py
+++ /dev/null
@@ -1,81 +0,0 @@
-import os
-import subprocess
-import tempfile
-import logging
-import papis.config
-import papis.commands.external
-
-
-main_vim_path = os.path.join(
- os.path.dirname(__file__),
- "main.vim"
-)
-
-pick_vim_path = os.path.join(
- os.path.dirname(__file__),
- "pick.vim"
-)
-
-
-def pick(
- options,
- header_filter=lambda x: x,
- body_filter=None,
- match_filter=lambda x: x
- ):
- if len(options) == 1:
- return options[0]
- if len(options) == 0:
- return None
- temp_file = tempfile.mktemp()
- fd = open(temp_file, "w+")
- headers = [
- header_filter(d) for d in
- options
- ]
- for header in headers:
- fd.write(header+"\n")
- fd.write("# Put your cursor on a line and press enter to pick\n")
- fd.close()
- subprocess.call(
- ["vim", "-S", pick_vim_path, temp_file]
- )
- fd = open(temp_file)
- index = fd.read()
- fd.close()
- ret = options[int(index)-1]
- return ret
-
-
-class Gui(object):
-
- def __init__(self):
- self.documents = []
- self.logger = logging.getLogger("gui:vim")
- self.main_vim_path = main_vim_path
-
- def export_variables(self, args):
- """Export variables so that vim can use some papis information
- """
- external_cmd = papis.commands.external.Command()
- external_cmd.set_args(args)
- external_cmd.export_variables()
-
- def main(self, documents, args):
- header_format = papis.config.get(
- "header-format",
- section="vim-gui"
- )
- self.export_variables(args)
- temp_file = tempfile.mktemp()
- self.logger.debug("Temp file = %s" % temp_file)
- fd = open(temp_file, "w+")
- for doc in documents:
- fd.write(
- papis.utils.format_doc(header_format, doc)
- )
- fd.close()
-
- subprocess.call(
- ["vim", "-S", self.main_vim_path, temp_file]
- )
diff --git a/papis/gui/vim/main.vim b/papis/gui/vim/main.vim
deleted file mode 100644
index 4fd24528..00000000
--- a/papis/gui/vim/main.vim
+++ /dev/null
@@ -1,143 +0,0 @@
-let g:papis_search_key = "/"
-let g:papis_next_search_key = "n"
-let g:papis_prev_search_key = "N"
-let g:papis_help_key = "h"
-let g:papis_delete_key = "dd"
-let g:papis_open_key = "o"
-let g:papis_open_dir_key = "<S-o>"
-let g:papis_edit_key = "e"
-
-let g:papis_next_key = "j"
-let g:papis_prev_key = "k"
-
-let g:papis_title_magic_word = "Title *:"
-let g:papis_author_magic_word = "Author:"
-let g:papis_year_magic_word = "Year :"
-let g:papis_tags_magic_word = "Tags :"
-let g:papis_document_separator = "^-------$"
-
-" Environment variables that should have been set by papis
-let g:papis_lib = $PAPIS_LIB
-let g:papis_lib_path = $PAPIS_LIB_PATH
-let g:papis_config_path = $PAPIS_CONFIG_PATH
-let g:papis_config_file = $PAPIS_CONFIG_FILE
-let g:papis_scripts_path = $PAPIS_SCRIPTS_PATH
-let g:papis_verbose = $PAPIS_VERBOSE
-
-" Set no modifiable
-"setlocal nomodifiable
-" Do not show line numbers, as they can be quite large
-setlocal nonumber
-setlocal nolist
-
-syntax match Comment "^[^:]*:"
-exe 'syntax region Statement start="'.g:papis_title_magic_word.'" contains=Comment end="$" keepend'
-syntax match Number "[0-9]\+"
-exe "syntax match Statement '".g:papis_document_separator."'"
-
-function! PapisGetIdentifier()
- " This function returns a paper identifier for the current entry
- let current_line = getline(".")
- if current_line =~ g:papis_title_magic_word.".*"
- let title_line = current_line
- endif
- "let start = line(".")
- "let end = search(g:papis_document_separator)
- "echom getline(start, end)
- let title_line = substitute(
- \ title_line,
- \ g:papis_title_magic_word,
- \ "", ""
- \ )
-
- return title_line
-endfunction
-
-function! PapisExeCommand(cmd, ...)
- let title_line = PapisGetIdentifier()
- let command = ":!papis -l ".g:papis_lib." ".a:cmd." ".join(a:000)." '".title_line."'"
- exe command
- redraw!
-endfunction
-
-function! PapisHelp()
- echomsg "Help - ".g:papis_help_key
- echomsg "Open - ".g:papis_open_key
- echomsg "Open dir - ".g:papis_open_dir_key
- echomsg "Edit - ".g:papis_edit_key
- echomsg "Search - ".g:papis_search_key
- echomsg "Delete - ".g:papis_delete_key
-endfunction
-
-function! PapisGo(direction)
- let back = "b"
- if a:direction == "next"
- let back = ""
- elseif a:direction == "prev"
- let back = "b"
- if 1 == line(".")
- return
- endif
- elseif a:direction == "bottom"
- exe ":normal! G"
- elseif a:direction == "screen-down"
- exe ":normal! \<C-f>"
- elseif a:direction == "screen-up"
- if 1 == line(".")
- return
- endif
- exe ":normal! \<C-b>"
- elseif a:direction == "half-down"
- exe ":normal! \<C-d>"
- elseif a:direction == "half-up"
- if 1 == line(".")
- return
- endif
- exe ":normal! \<C-u>"
- endif
- call cursor(search(g:papis_title_magic_word, back), 0)
- exe ":normal! zt"
-endfunction
-
-function! PapisSearch(...)
- "set nohlsearch
- if len(a:000) == 0
- let @/ = "\\c".substitute(input("Search: "), " *", ".*", "g")
- exec "normal! n"
- elseif a:000[0] == "n"
- exec "normal! nn"
- else
- exec "normal! N"
- endif
- set hlsearch
- call PapisGo("next")
- call PapisGo("prev")
-endfunction
-
-exec "nnoremap <buffer> ".g:papis_search_key." :call PapisSearch()<cr>"
-exec "nnoremap <buffer> ".g:papis_next_search_key." :call PapisSearch('n')<cr>"
-exec "nnoremap <buffer> ".g:papis_prev_search_key." :call PapisSearch('p')<cr>"
-exec "nnoremap <buffer> f :call PapisSearch()<cr>"
-exec "nnoremap <buffer> ".g:papis_help_key." :call PapisHelp()<cr>"
-exec "nnoremap <buffer> ".g:papis_open_key." :silent call PapisExeCommand('open')<cr>"
-exec "nnoremap <buffer> ".g:papis_delete_key." :silent call PapisExeCommand('rm')<cr>"
-exec "nnoremap <buffer> <Return> :silent call PapisExeCommand('open')<cr>"
-exec "nnoremap <buffer> ".g:papis_open_dir_key." :silent call PapisExeCommand('open', '--dir')<cr>"
-exec "nnoremap <buffer> ".g:papis_edit_key." :silent call PapisExeCommand('edit')<cr>"
-
-exec "nnoremap <buffer> ".g:papis_next_key." :silent call PapisGo('next')<cr>"
-exec "nnoremap <buffer> ".g:papis_prev_key." :silent call PapisGo('prev')<cr>"
-nnoremap <buffer> <Up> :silent call PapisGo('prev')<cr>
-nnoremap <buffer> <Down> :silent call PapisGo('next')<cr>
-nnoremap <buffer> <S-g> :silent call PapisGo("bottom")<cr>
-nnoremap <buffer> <C-d> :silent call PapisGo("half-down")<cr>
-nnoremap <buffer> <C-u> :silent call PapisGo("half-up")<cr>
-nnoremap <buffer> <C-f> :silent call PapisGo("screen-down")<cr>
-nnoremap <buffer> <C-b> :silent call PapisGo("screen-up")<cr>
-
-nnoremap <buffer> q :quit<cr>
-command! -nargs=0 PapisHelp call PapisHelp()
-command! -nargs=0 PapisOpen call PapisExeCommand("open")
-command! -nargs=0 PapisOpenDir call PapisExeCommand("open", '--dir')
-command! -nargs=0 PapisBrowse call PapisExeCommand("browse")
-command! -nargs=0 PapisEdit call PapisExeCommand("edit")
diff --git a/papis/gui/vim/pick.vim b/papis/gui/vim/pick.vim
deleted file mode 100644
index f1fe3671..00000000
--- a/papis/gui/vim/pick.vim
+++ /dev/null
@@ -1,14 +0,0 @@
-function! Pick()
- exe ":.s/.*/".line(".")
- if line(".") != 1
- :normal! kdgg
- endif
- if line(".") != line("$")
- :normal! jdG
- endif
- :write
- :quit
-endfunction
-
-nnoremap <Return> :call Pick()<cr>
-syntax match Comment "^#.*$"
diff --git a/setup.py b/setup.py
index 74e1ed8b..cfbae4aa 100644
--- a/setup.py
+++ b/setup.py
@@ -77,7 +77,6 @@ setup(
# for example:
# $ pip install -e .[develop]
optional=[
- 'dmenu',
"Jinja2>=2.10",
"Whoosh>=2.7.4",
],
@@ -102,8 +101,6 @@ setup(
],
package_data=dict(
papis=[
- 'gui/vim/main.vim',
- 'gui/vim/pick.vim',
],
),
data_files=[
@@ -127,8 +124,6 @@ setup(
],
packages=[
"papis",
- "papis.gui",
- "papis.gui.vim",
"papis.commands",
"papis.database",
"papis.downloaders",
diff --git a/tests/commands/test_config.py b/tests/commands/test_config.py
index 6fcdaf07..b1a5cca8 100644
--- a/tests/commands/test_config.py
+++ b/tests/commands/test_config.py
@@ -11,11 +11,10 @@ class TestCommand(unittest.TestCase):
def test_simple(self):
self.assertTrue(run('editor') == papis.config.get('editor'))
- self.assertTrue(run('xeditor') == papis.config.get('xeditor'))
- self.assertTrue(run('settings.xeditor') == papis.config.get('xeditor'))
+ self.assertTrue(run('settings.editor') == papis.config.get('editor'))
self.assertTrue(
- run('dmenu-gui.lines') ==
- papis.config.get('lines', section='dmenu-gui')
+ run('papers.dir') ==
+ papis.config.get('dir', section='papers')
)
@@ -29,20 +28,6 @@ class TestDefaultConfiguration(unittest.TestCase):
def tearDownClass(self):
pass
- def test_gui_default_config(self):
- """Test that the gui has a method to get default config
- """
- import papis.gui
- # Function exists
- self.assertTrue(papis.gui.get_default_settings)
-
- settings = papis.gui.get_default_settings()
- self.assertTrue(settings)
-
- self.assertTrue(isinstance(settings, dict))
- for section in ["vim-gui"]:
- self.assertTrue(section in settings.keys())
-
def test_default_config(self):
"""Test main default config
"""
@@ -52,7 +37,7 @@ class TestDefaultConfiguration(unittest.TestCase):
self.assertTrue(settings)
self.assertTrue(isinstance(settings, dict))
- for section in ["settings", "vim-gui"]:
+ for section in ["settings"]:
self.assertTrue(section in settings.keys())
def test_set_lib(self):