summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--bog-tests.el41
-rw-r--r--bog.el71
3 files changed, 63 insertions, 55 deletions
diff --git a/Makefile b/Makefile
index fbcd942..d85bb40 100644
--- a/Makefile
+++ b/Makefile
@@ -6,13 +6,13 @@ BATCH = $(EMACS) -Q --batch $(LOAD_PATH)
all: bog.elc bog-autoloads.el
.PHONY: test
-test: bog.elc
- @$(BATCH) -L . -l bog-tests.el \
+test: bog.elc bog-tests.elc
+ @$(BATCH) -L . -l bog-tests.elc \
--eval "(ert-run-tests-batch-and-exit '(not (tag interactive)))"
.PHONY: clean
clean:
- $(RM) bog.elc bog-autoloads.el
+ $(RM) bog.elc bog-autoloads.el bog-tests.elc
%.elc: %.el
@$(BATCH) -L . -f batch-byte-compile $<
diff --git a/bog-tests.el b/bog-tests.el
index b1b2ea1..3a1539c 100644
--- a/bog-tests.el
+++ b/bog-tests.el
@@ -1,4 +1,4 @@
-;;; bog-tests.el --- Tests for Bog
+;;; bog-tests.el --- Tests for Bog -*- lexical-binding: t -*-
;; Copyright (C) 2013-2016 Kyle Meyer <kyle@kyleam.com>
@@ -19,15 +19,17 @@
;;; Code:
+(require 'bog)
(require 'ert)
(require 'org)
-(require 'cl-lib)
-(require 'bog)
+
+(with-no-warnings ;; Silence "lacks a prefix" warning.
+ (defvar citekey))
;; Modified from magit-tests.el.
(defmacro bog-tests-with-temp-dir (&rest body)
(declare (indent 0) (debug t))
- (let ((dir (cl-gensym)))
+ (let ((dir (make-symbol "dir")))
`(let ((,dir (file-name-as-directory (make-temp-file "dir" t))))
(unwind-protect
(let ((default-directory ,dir)) ,@body)
@@ -44,21 +46,18 @@ value of the variable `citekey'.
If the string \"<point>\" appears in TEXT then remove it and
place the point there before running BODY, otherwise place the
point at the beginning of the inserted text."
- (declare (indent 1))
- `(let* ((inside-text (if (stringp ,text) ,text (eval ,text)))
- (is-citekey (string-match "<citekey>" inside-text)))
- (when (and is-citekey citekey)
- (setq inside-text (replace-match citekey nil nil inside-text)))
- (with-temp-buffer
- (org-mode)
- (let ((point (string-match "<point>" inside-text)))
- (if point
- (progn
- (insert (replace-match "" nil nil inside-text))
- (goto-char (1+ (match-beginning 0))))
- (insert inside-text)
- (goto-char (point-min))))
- ,@body)))
+ (declare (indent 1) (debug t))
+ `(with-temp-buffer
+ (org-mode)
+ (insert ,text)
+ (goto-char (point-min))
+ (when (and (bound-and-true-p citekey)
+ (search-forward "<citekey>" nil t))
+ (replace-match citekey t t))
+ (goto-char (point-min))
+ (when (search-forward "<point>" nil t)
+ (replace-match "" t t))
+ ,@body))
;;; Citekey functions
@@ -410,7 +409,7 @@ some text"
(concat citekey ".txt")
(concat citekey "_0.pdf")
(concat citekey "-supplement.pdf")))
- found-files)
+ files-found)
(make-directory bog-file-directory)
(dolist (var variants)
(write-region "" nil (expand-file-name var bog-file-directory)))
@@ -582,3 +581,5 @@ some text"
(sort (bog--find-duplicates
(list "a" "b" "c" "b" "a"))
#'string-lessp))))
+
+;;; bog-tests.el ends here
diff --git a/bog.el b/bog.el
index e7ceada..2739caf 100644
--- a/bog.el
+++ b/bog.el
@@ -1,4 +1,4 @@
-;;; 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>
@@ -133,7 +133,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 +180,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 +348,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 +463,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
@@ -1181,25 +1181,32 @@ 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))
+ (org-lprops (make-symbol "org-lprops")))
+ `(let ((,org-lprops (get 'org-agenda-redo-command 'org-lprops)))
+ (unwind-protect
+ (let ,bog-lprops
+ (put 'org-agenda-redo-command 'org-lprops ',bog-lprops)
+ (put 'org-agenda-files 'org-restrict nil)
+ ,@body
+ (use-local-map bog--agenda-map))
+ (put 'org-agenda-redo-command 'org-lprops ,org-lprops)))))
;;;###autoload
(defun bog-search-notes (&optional todo-only string)
@@ -1209,7 +1216,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 +1237,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 +1272,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
@@ -1403,7 +1410,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.")
@@ -1430,11 +1437,11 @@ if ARG is omitted or nil.
(cond
(bog-mode
(if (derived-mode-p 'org-mode)
- (add-hook 'org-font-lock-hook 'bog-fontify-non-heading-citekeys)
+ (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)
+ (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))))