From 2c7aba4d7f3afa0aef2502266898244848d95ea8 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 1 May 2014 21:58:20 -0400 Subject: Add Bog commander --- README | 5 ++++ README.md | 7 +++++- bog.el | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/README b/README index 95c7776..85fcef6 100644 --- a/README +++ b/README @@ -138,3 +138,8 @@ The variables below are important for specifying how Bog behaves. A keymap is defined for Bog under the prefix =C-c "​=. If you prefer something else (like =C-c b=), set =bog-keymap-prefix=. + +Some Bog functions are useful outside of an Org buffer (e.g., +=bog-search-notes=). These functions are available through the +=bog-commander= interface (based of off the =projectile-commander=). +This can be bound to a global key for quick access. diff --git a/README.md b/README.md index 7cfa868..2ded111 100644 --- a/README.md +++ b/README.md @@ -124,4 +124,9 @@ The variables below are important for specifying how Bog behaves. # Keybindings A keymap is defined for Bog under the prefix `C-c "​`. If you prefer -something else (like `C-c b`), set `bog-keymap-prefix`. \ No newline at end of file +something else (like `C-c b`), set `bog-keymap-prefix`. + +Some Bog functions are useful outside of an Org buffer (e.g., +`bog-search-notes`). These functions are available through the +`bog-commander` interface (based of off the `projectile-commander`). +This can be bound to a global key for quick access. \ No newline at end of file diff --git a/bog.el b/bog.el index c648bd2..45e7db7 100644 --- a/bog.el +++ b/bog.el @@ -729,6 +729,86 @@ Sorting is only done if the heading's level matches '((bog-non-heading-citekey-p . 'bog-citekey-face))) (font-lock-fontify-buffer)) + +;;; Commander + +;;; The commander functionality is taken from projectile. +;;; https://github.com/bbatsov/projectile + +(defconst bog-commander-help-buffer "*Commander Help*") + +(defvar bog-commander-methods nil + "List of file-selection methods for the `bog-commander' command. +Each element is a list (KEY DESCRIPTION FUNCTION). +DESCRIPTION is a one-line description of what the key selects.") + +;;;###autoload +(defun bog-commander () + "Execute a Bog command with a single letter. + +The user is prompted for a single character indicating the action +to invoke. Press \"?\" to describe available actions. + +See `def-bog-commander-method' for defining new methods." + (interactive) + (message "Commander [%s]: " + (apply #'string (mapcar #'car bog-commander-methods))) + (let* ((ch (save-window-excursion + (select-window (minibuffer-window)) + (read-char))) + (method (cl-find ch bog-commander-methods :key #'car))) + (cond (method + (funcall (cl-caddr method))) + (t + (message "No method for character: ?\\%c" ch) + (ding) + (sleep-for 1) + (discard-input) + (bog-commander))))) + +(defmacro def-bog-commander-method (key description &rest body) + "Define a new `bog-commander' method. + +KEY is the key the user will enter to choose this method. + +DESCRIPTION is a one-line sentence describing the method. + +BODY is a series of forms which are evaluated when the method is +chosen." + (let ((method `(lambda () + ,@body))) + `(setq bog-commander-methods + (cl-sort (cons (list ,key ,description ,method) + (cl-remove ,key bog-commander-methods :key #'car)) + #'< :key #'car)))) + +(def-bog-commander-method ?? "Commander help buffer." + (ignore-errors (kill-buffer bog-commander-help-buffer)) + (with-current-buffer (get-buffer-create bog-commander-help-buffer) + (insert "Bog commander methods:\n\n") + (loop for (key line nil) in bog-commander-methods + do (insert (format "%c:\t%s\n" key line))) + (goto-char (point-min)) + (help-mode) + (display-buffer (current-buffer) t)) + (bog-commander)) + +(def-bog-commander-method ?b + "Find citekey BibTeX file." + (bog-find-citekey-bib t)) + +(def-bog-commander-method ?f + "Find citekey file." + (bog-find-citekey-file t)) + +(def-bog-commander-method ?h + "Find citekey heading in notes." + (bog-goto-citekey-heading-in-notes t)) + +(def-bog-commander-method ?s + "Search Bog notes with `org-search-view'." + (bog-search-notes)) + ;;; Minor mode -- cgit v1.2.3 From e244edff767b1d19d95820f5adbdda3853f42ab2 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 1 May 2014 21:58:43 -0400 Subject: Remove Bog agenda command --- bog.el | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/bog.el b/bog.el index 45e7db7..7ca3ec5 100644 --- a/bog.el +++ b/bog.el @@ -186,17 +186,6 @@ level to operate on." :group 'bog :type 'string) -(defcustom bog-agenda-custom-command-key "b" - "Key to use for Bog notes search key in agenda dispatch. -If nil, a custom command will not be added to Org agenda -dispatch, but searching Bog notes through the agenda interface -will still be available through `bog-search-notes' and -`bog-search-notes-for-citekey'." - :group 'bog - :type '(choice - (const :tag "Don't display in agenda dispatch" nil) - (string :tag "Key for agenda dispatch"))) - ;;; Citekey methods @@ -667,7 +656,8 @@ level `bog-refile-maxlevel' are considered." "Search notes using `org-search-view'. With prefix argument TODO-ONLY, only TODO entries are searched." (interactive "P") - (let ((lprops (nth 4 bog-agenda-custom-command))) + (let ((lprops '((org-agenda-files (bog-notes-files)) + (org-agenda-text-search-extra-files nil)))) (put 'org-agenda-redo-command 'org-lprops lprops) (org-let lprops '(org-search-view todo-only)))) @@ -676,7 +666,8 @@ With prefix argument TODO-ONLY, only TODO entries are searched." With prefix argument TODO-ONLY, only TODO entries are searched." (interactive "P") (let ((citekey (bog-citekey-from-notes)) - (lprops (nth 4 bog-agenda-custom-command))) + (lprops '((org-agenda-files (bog-notes-files)) + (org-agenda-text-search-extra-files nil)))) (put 'org-agenda-redo-command 'org-lprops lprops) (org-let lprops '(org-search-view todo-only citekey)))) @@ -828,11 +819,6 @@ chosen." map) "Keymap for Bog.") -(defvar bog-agenda-custom-command - `(,(or bog-agenda-custom-command-key "b") "Search Bog notes" search "" - ((org-agenda-files (bog-notes-files)) - (org-agenda-text-search-extra-files nil)))) - ;;;###autoload (define-minor-mode bog-mode "Toggle Bog in this buffer. @@ -847,15 +833,9 @@ ARG is omitted or nil. :require 'bog (cond (bog-mode - (bog-add-fontlock) - (when bog-agenda-custom-command-key - (add-to-list 'org-agenda-custom-commands - bog-agenda-custom-command))) + (bog-add-fontlock)) (t - (bog-remove-fontlock) - (when bog-agenda-custom-command - (setq org-agenda-custom-commands (delete bog-agenda-custom-command - org-agenda-custom-commands)))))) + (bog-remove-fontlock)))) (provide 'bog) -- cgit v1.2.3 From bd9e0e763db3d7cca9cc14a2f673ee03631456bc Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 1 May 2014 22:16:31 -0400 Subject: Add NEWS for Bog commander --- NEWS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS b/NEWS index c38895c..7f77346 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,11 @@ - When locating a citekey from the notes fails, functions will now prompt with a list of citekeys instead of giving an error. +- Bog commands are now available outside of Org buffers through + =bog-commander=. This is based off of =projectile-commander=. The + custom Bog commands for the Org agenda have been removed because this + functionality is now available through =bog-commander=. + * v0.6.0 ** New features -- cgit v1.2.3