summaryrefslogtreecommitdiff
path: root/bog.el
diff options
context:
space:
mode:
authorBasil L. Contovounesios <contovob@tcd.ie>2020-06-26 09:28:38 +0100
committerBasil L. Contovounesios <contovob@tcd.ie>2020-06-26 09:28:38 +0100
commit2dbe3ccb1bc5e94188a3c180165198ad63c1f1f9 (patch)
tree225d2799009748eceb367fccc808b8b5a3a548e5 /bog.el
parent6c8fa1b4961e279ae63130902996c5f71a2e64e4 (diff)
parentc2cbbd99e2b6b9b79c15acec025333089dbea920 (diff)
downloadbog-2dbe3ccb1bc5e94188a3c180165198ad63c1f1f9.tar.gz
Merge branch 'blc/lex' [#12]
Diffstat (limited to 'bog.el')
-rw-r--r--bog.el105
1 files changed, 55 insertions, 50 deletions
diff --git a/bog.el b/bog.el
index e7ceada..2e1d5d9 100644
--- a/bog.el
+++ b/bog.el
@@ -1,6 +1,7 @@
-;;; bog.el --- Extensions for research notes in Org mode
+;;; bog.el --- Extensions for research notes in Org mode -*- lexical-binding: t -*-
;; Copyright (C) 2013-2016 Kyle Meyer <kyle@kyleam.com>
+;; Copyright (C) 2020 Basil L. Contovounesios <contovob@tcd.ie>
;; Author: Kyle Meyer <kyle@kyleam.com>
;; URL: https://github.com/kyleam/bog
@@ -133,7 +134,7 @@ non-nil."
rename."
:type 'directory)
-(defcustom bog-find-citekey-bib-func 'bog-find-citekey-bib-file
+(defcustom bog-find-citekey-bib-func #'bog-find-citekey-bib-file
"Function used to find BibTeX entry for citekey.
Default is `bog-find-citekey-bib-file', which locates single
@@ -180,7 +181,7 @@ files with the format <citekey>.* and <citekey><sep>*.<ext>,
where <sep> is matched by this regular expression.."
:type 'regexp)
-(defcustom bog-file-renaming-func 'bog-file-ask-on-conflict
+(defcustom bog-file-renaming-func #'bog-file-ask-on-conflict
"Function used to rename staged files.
This function should accept a file name and a citekey as
arguments and return the name of the final file. Currently the
@@ -348,8 +349,8 @@ Keys match values in `bog-use-citekey-cache'.")
"Execute BODY, maybe using cached citekey values for KEY.
Use cached values if `bog-use-citekey-cache' is non-nil for KEY.
Cached values are updated to the return values of BODY."
- (declare (indent 1))
- (let ((use-cache-p (cl-gensym "use-cache-p")))
+ (declare (indent 1) (debug t))
+ (let ((use-cache-p (make-symbol "use-cache-p")))
`(let* ((,use-cache-p (bog--use-cache-p ,key))
(citekeys (or (and ,use-cache-p
(cdr (assq ,key bog--citekey-cache)))
@@ -463,11 +464,11 @@ behavior:
,(format "Select citekey with `%s'.
Fall back on `%s'.
If NO-CONTEXT is non-nil, immediately fall back."
- (symbol-name context-method)
- (symbol-name collection-method))
- (or (and no-context (bog-select-citekey (,collection-method)))
- (,context-method)
- (bog-select-citekey (,collection-method)))))
+ context-method
+ collection-method)
+ (or (and no-context (bog-select-citekey (,collection-method)))
+ (,context-method)
+ (bog-select-citekey (,collection-method)))))
(bog-selection-method "surroundings-or-files"
bog-citekey-from-surroundings
@@ -499,8 +500,10 @@ If NO-CONTEXT is non-nil, immediately fall back."
;;;; Other
;; `show-all' is obsolete as of Emacs 25.1.
-(unless (fboundp 'outline-show-all)
- (defalias 'outline-show-all 'show-all))
+(defalias 'bog--outline-show-all
+ (if (fboundp 'outline-show-all)
+ #'outline-show-all
+ 'show-all))
(defun bog--set-difference (list1 list2)
(let ((sdiff (cl-set-difference list1 list2 :test #'string=)))
@@ -532,7 +535,7 @@ file."
(mapconcat #'identity nohead-cks "\n"))))))
(org-mode)
(bog-mode 1)
- (outline-show-all)
+ (bog--outline-show-all)
(goto-char (point-min)))
(pop-to-buffer bufname)))
@@ -1142,7 +1145,7 @@ If the citekey prompt is slow to appear, consider enabling the
(citekey (bog-citekey-from-point-or-all-headings no-context))
(marker (with-current-buffer (or (buffer-base-buffer)
(current-buffer))
- (bog--find-citekey-heading-in-notes citekey))))
+ (bog--find-citekey-heading-in-notes citekey))))
(if marker
(with-current-buffer (marker-buffer marker)
(org-with-wide-buffer
@@ -1181,25 +1184,28 @@ level `bog-refile-maxlevel' are considered."
(cdr (assoc-string (completing-read "File: " note-paths)
note-paths))))
+(defvar bog--agenda-map
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map org-agenda-mode-map)
+ (define-key map "r" 'bog-agenda-redo)
+ (define-key map "g" 'bog-agenda-redo)
+ map)
+ "Local keymap for Bog-related agendas.")
+
(defmacro bog--with-search-lprops (&rest body)
"Execute BODY with Bog-related agenda values.
Restore the `org-lprops' property value for
`org-agenda-redo-command' after executing BODY."
- (declare (indent 0))
- `(let ((org-lprops (get 'org-agenda-redo-command 'org-lprops))
- (bog-lprops '((org-agenda-buffer-name "*Bog search*")
- (org-agenda-files (bog-notes))
- org-agenda-text-search-extra-files
- org-agenda-sticky)))
- (put 'org-agenda-redo-command 'org-lprops bog-lprops)
- (put 'org-agenda-files 'org-restrict nil)
- (org-let bog-lprops ,@body)
- (use-local-map (let ((map (make-sparse-keymap)))
- (set-keymap-parent map org-agenda-mode-map)
- (define-key map "r" 'bog-agenda-redo)
- (define-key map "g" 'bog-agenda-redo)
- map))
- (put 'org-agenda-redo-command 'org-lprops org-lprops)))
+ (declare (indent 0) (debug t))
+ (let ((bog-lprops '((org-agenda-buffer-name "*Bog search*")
+ (org-agenda-files (bog-notes))
+ (org-agenda-text-search-extra-files ())
+ (org-agenda-sticky nil))))
+ `(cl-letf (((get 'org-agenda-redo-command 'org-lprops) ',bog-lprops)
+ ,@bog-lprops)
+ (put 'org-agenda-files 'org-restrict nil)
+ ,@body
+ (use-local-map bog--agenda-map))))
;;;###autoload
(defun bog-search-notes (&optional todo-only string)
@@ -1209,7 +1215,7 @@ STRING is non-nil, use it as the search term (instead of
prompting for one)."
(interactive "P")
(bog--with-search-lprops
- '(org-search-view todo-only string)))
+ (org-search-view todo-only string)))
;;;###autoload
(defun bog-search-notes-for-citekey (&optional todo-only)
@@ -1230,7 +1236,7 @@ If the citekey prompt is slow to appear, consider enabling the
(defun bog-agenda-redo (&optional all)
(interactive "P")
(bog--with-search-lprops
- '(org-agenda-redo all)))
+ (org-agenda-redo all)))
(defun bog-sort-topic-headings-in-buffer (&optional sorting-type)
"Sort topic headings in this buffer.
@@ -1265,8 +1271,8 @@ argument CURRENT-BUFFER, limit to heading citekeys from the
current buffer."
(interactive "P")
(let ((citekey-func (if current-buffer
- 'bog-heading-citekeys-in-wide-buffer
- 'bog-all-heading-citekeys)))
+ #'bog-heading-citekeys-in-wide-buffer
+ #'bog-all-heading-citekeys)))
(insert (bog-select-citekey (funcall citekey-func)))))
;;;###autoload
@@ -1357,7 +1363,7 @@ Topic headings are determined by `bog-topic-heading-level'."
;;; Font-lock
(defface bog-citekey-face
- '((t (:inherit org-link :underline nil)))
+ '((t :inherit org-link :underline nil))
"Face used to highlight text that matches `bog-citekey-format'.")
(defun bog-fontify-non-heading-citekeys (limit)
@@ -1374,7 +1380,7 @@ Topic headings are determined by `bog-topic-heading-level'."
(defvar bog-citekey-font-lock-keywords
'((bog-fontify-non-heading-citekeys . bog-citekey-face)))
-(defvar bog-font-lock-function
+(defalias 'bog--font-lock-function
(if (fboundp 'font-lock-flush)
#'font-lock-flush
#'font-lock-fontify-buffer))
@@ -1403,7 +1409,7 @@ Topic headings are determined by `bog-topic-heading-level'."
(define-key map "v" 'bog-view-mode)
(define-key map "y" 'bog-insert-heading-citekey)
map)
- "Map for Bog commands.
+ "Keymap for Bog commands.
In Bog mode, these are under `bog-keymap-prefix'.
`bog-command-map' can also be bound to a key outside of Bog
mode.")
@@ -1426,20 +1432,19 @@ if ARG is omitted or nil.
\\{bog-mode-map}"
:lighter " Bog"
- (progn
- (cond
- (bog-mode
- (if (derived-mode-p 'org-mode)
- (add-hook 'org-font-lock-hook 'bog-fontify-non-heading-citekeys)
- (font-lock-add-keywords nil bog-citekey-font-lock-keywords)))
- (t
- (if (derived-mode-p 'org-mode)
- (remove-hook 'org-font-lock-hook 'bog-fontify-non-heading-citekeys)
- (font-lock-remove-keywords nil bog-citekey-font-lock-keywords))
- (when (bound-and-true-p bog-view-mode)
- (bog-view-mode -1))))
- (when font-lock-mode
- (funcall bog-font-lock-function))))
+ (cond
+ (bog-mode
+ (if (derived-mode-p 'org-mode)
+ (add-hook 'org-font-lock-hook #'bog-fontify-non-heading-citekeys nil t)
+ (font-lock-add-keywords nil bog-citekey-font-lock-keywords)))
+ (t
+ (if (derived-mode-p 'org-mode)
+ (remove-hook 'org-font-lock-hook #'bog-fontify-non-heading-citekeys t)
+ (font-lock-remove-keywords nil bog-citekey-font-lock-keywords))
+ (when (bound-and-true-p bog-view-mode)
+ (bog-view-mode -1))))
+ (when font-lock-mode
+ (bog--font-lock-function)))
;;; View minor mode