From b173d8a2414180c6183fd3906996936a35ecb253 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 30 Mar 2014 02:12:09 -0400 Subject: Define minor mode for Bog --- README.md | 7 ++----- bog-readme.org | 9 ++------- bog.el | 50 +++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 916b71d..36d9d71 100644 --- a/README.md +++ b/README.md @@ -112,8 +112,5 @@ The variables below are important for specifying how Bog behaves. # Keybindings -A keymap is defined for Bog, but a prefix isn't claimed. The code below -shows how to use "C-c b" as the prefix while in Org mode. - - (eval-after-load 'org - '(define-key org-mode-map (kbd "C-c b") bog-mode-map)) \ No newline at end of file +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 diff --git a/bog-readme.org b/bog-readme.org index 9e18fd3..737db31 100644 --- a/bog-readme.org +++ b/bog-readme.org @@ -120,10 +120,5 @@ The variables below are important for specifying how Bog behaves. * Keybindings -A keymap is defined for Bog, but a prefix isn't claimed. The code below -shows how to use "C-c b" as the prefix while in Org mode. - -#+begin_src emacs-lisp - (eval-after-load 'org - '(define-key org-mode-map (kbd "C-c b") bog-mode-map)) -#+end_src +A keymap is defined for Bog under the prefix `C-c "'. If you prefer +something else (like `C-c b'), set =bog-keymap-prefix=. diff --git a/bog.el b/bog.el index 99694c3..308ed34 100644 --- a/bog.el +++ b/bog.el @@ -176,6 +176,11 @@ It should contain the placeholder \"%s\" for the query." :group 'bog :type 'integer) +(defcustom bog-keymap-prefix (kbd "C-c \"") + "Bog keymap prefix." + :group 'bog + :type 'string) + ;;; General utilities @@ -542,23 +547,50 @@ level `bog-refile-maxlevel' are considered." (and (re-search-forward bog-citekey-format limit t) (not (org-at-heading-p)))) -(font-lock-add-keywords 'org-mode - '((bog-non-heading-citekey-p . 'bog-citekey-face))) +(defun bog-add-fontlock () + (font-lock-add-keywords nil + '((bog-non-heading-citekey-p . 'bog-citekey-face))) + (font-lock-fontify-buffer)) + +(defun bog-remove-fontlock () + (font-lock-remove-keywords nil + '((bog-non-heading-citekey-p . 'bog-citekey-face))) + (font-lock-fontify-buffer)) -;;; Keymap +;;; Minor mode (defvar bog-mode-map (let ((map (make-sparse-keymap))) - (define-key map "p" 'bog-find-citekey-pdf) - (define-key map "r" 'bog-rename-staged-pdf-to-citekey) - (define-key map "b" 'bog-find-citekey-bib) - (define-key map "h" 'bog-goto-citekey-heading-in-buffer) - (define-key map "H" 'bog-goto-citekey-heading-in-notes) - (define-key map "w" 'bog-search-citekey-on-web) + (let ((prefix-map (make-sparse-keymap))) + (define-key prefix-map "p" 'bog-find-citekey-pdf) + (define-key prefix-map "r" 'bog-rename-staged-pdf-to-citekey) + (define-key prefix-map "b" 'bog-find-citekey-bib) + (define-key prefix-map "h" 'bog-goto-citekey-heading-in-buffer) + (define-key prefix-map "H" 'bog-goto-citekey-heading-in-notes) + (define-key prefix-map "w" 'bog-search-citekey-on-web) + (define-key map bog-keymap-prefix prefix-map)) map) "Keymap for Bog.") +;;;###autoload +(define-minor-mode bog-mode + "Toggle Bog in this buffer. +With a prefix argument ARG, enable `bog-mode' if ARG is positive, +and disable it otherwise. If called from Lisp, enable the mode if +ARG is omitted or nil. + +\\{bog-mode-map}" + :keymap bog-mode-map + :group 'bog + :lighter " Bog" + :require 'bog + (cond + (bog-mode + (bog-add-fontlock)) + (t + (bog-remove-fontlock)))) + (provide 'bog) ;; bog.el ends here -- cgit v1.2.3