diff options
author | Kyle Meyer <kyle@kyleam.com> | 2014-12-11 00:19:01 -0500 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2014-12-11 00:19:01 -0500 |
commit | 7688cb0c61a757baab5fe830ed12520cb54756ae (patch) | |
tree | 9110bc35caf13e0ae6fab0d9b7b7fa6ca27bba0e | |
parent | ebef5b183c959c2e228ca4c7f8107bec517d2582 (diff) | |
download | bog-7688cb0c61a757baab5fe830ed12520cb54756ae.tar.gz |
Add commands bog-{next,previous}-non-heading-citekey
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | bog-tests.el | 59 | ||||
-rw-r--r-- | bog.el | 32 |
3 files changed, 94 insertions, 0 deletions
@@ -31,6 +31,9 @@ link in the citekey's subtree. The citekey is either taken from at point or selected from all heading citekeys. +- New commands =bog-next-non-heading-citekey= and + =bog-previous-non-heading-citekey= + ** Other changes - =bog-goto-citekey-heading-in-buffer= and diff --git a/bog-tests.el b/bog-tests.el index 0173c5f..91bf252 100644 --- a/bog-tests.el +++ b/bog-tests.el @@ -254,6 +254,65 @@ some text and <point><citekey>" ** second" (should-not (bog-citekey-from-surroundings)))) +;; bog-{next,previous}-non-heading-citekey + +(ert-deftest bog-next-non-heading-citekey-default-arg () + (let ((citekey "name2010word")) + (bog-tests--with-temp-text + " +<point> +<citekey> other2000key" + (bog-next-non-heading-citekey) + (should (equal citekey (bog-citekey-at-point)))))) + +(ert-deftest bog-next-non-heading-citekey-pos-arg () + (let ((citekey "name2010word")) + (bog-tests--with-temp-text + " +<point> +other2000key <citekey>" + (bog-next-non-heading-citekey 2) + (should (equal citekey (bog-citekey-at-point)))))) + +(ert-deftest bog-next-non-heading-citekey-on-citekey () + (let ((citekey "name2010word")) + (bog-tests--with-temp-text + " +<point>other2000key +<citekey>" + (bog-next-non-heading-citekey) + (should (equal citekey (bog-citekey-at-point)))))) + +(ert-deftest bog-next-non-heading-citekey-pos-neg-arg () + (let ((citekey "name2010word")) + (bog-tests--with-temp-text + "<citekey> <point>" + (bog-next-non-heading-citekey -1) + (should (equal citekey (bog-citekey-at-point)))))) + +(ert-deftest bog-previous-non-heading-citekey-default-arg () + (let ((citekey "name2010word")) + (bog-tests--with-temp-text + "other2000key <citekey> <point>" + (bog-previous-non-heading-citekey) + (should (equal citekey (bog-citekey-at-point)))))) + +(ert-deftest bog-previous-non-heading-citekey-on-citekey () + (let ((citekey "name2010word")) + (bog-tests--with-temp-text + " +<citekey> +<point>other2000key" + (bog-previous-non-heading-citekey) + (should (equal citekey (bog-citekey-at-point)))))) + +(ert-deftest bog-previous-non-heading-citekey-pos-arg () + (let ((citekey "name2010word")) + (bog-tests--with-temp-text + "<citekey> other2000key <point>" + (bog-previous-non-heading-citekey 2) + (should (equal citekey (bog-citekey-at-point)))))) + ;;; File functions @@ -820,6 +820,36 @@ be opened if locating a citekey from context fails." (org-open-at-point))) (message "Heading for %s not found in notes" citekey)))) +(defun bog-next-non-heading-citekey (&optional arg) + "Move foward to next non-heading citekey. +With argument ARG, do it ARG times." + (interactive "p") + (or arg (setq arg 1)) + (if (< arg 0) + (bog-previous-non-heading-citekey (- arg)) + (bog--with-citekey-syntax + (skip-syntax-forward "w") + (let (case-fold-search) + (while (and (> arg 0) + (re-search-forward bog-citekey-format nil t)) + (unless (org-at-heading-p) + (setq arg (1- arg)))))) + (org-show-context))) + +(defun bog-previous-non-heading-citekey (&optional arg) + "Move backward to previous non-heading citekey. +With argument ARG, do it ARG times." + (interactive "p") + (or arg (setq arg 1)) + (bog--with-citekey-syntax + (let (case-fold-search) + (while (and (> arg 0) + (re-search-backward bog-citekey-format nil t)) + (unless (org-at-heading-p) + (setq arg (1- arg))))) + (skip-syntax-backward "w")) + (org-show-context)) + ;;; Font-lock @@ -919,6 +949,8 @@ chosen." (define-key prefix-map "H" 'bog-goto-citekey-heading-in-notes) (define-key prefix-map "i" 'bog-citekey-tree-to-indirect-buffer) (define-key prefix-map "l" 'bog-open-first-citekey-link) + (define-key prefix-map "n" 'bog-next-non-heading-citekey) + (define-key prefix-map "p" 'bog-previous-non-heading-citekey) (define-key prefix-map "r" 'bog-rename-staged-file-to-citekey) (define-key prefix-map "s" 'bog-search-notes) (define-key prefix-map "w" 'bog-refile) |