From 7688cb0c61a757baab5fe830ed12520cb54756ae Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 11 Dec 2014 00:19:01 -0500 Subject: Add commands bog-{next,previous}-non-heading-citekey --- NEWS | 3 +++ bog-tests.el | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bog.el | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/NEWS b/NEWS index 7c453f1..16d4920 100644 --- a/NEWS +++ b/NEWS @@ -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 " ** 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 + " + + 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 + " + +other2000key " + (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 + " +other2000key +" + (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 + " " + (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 " + (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 + " + +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 + " other2000key " + (bog-previous-non-heading-citekey 2) + (should (equal citekey (bog-citekey-at-point)))))) + ;;; File functions diff --git a/bog.el b/bog.el index e25d7ae..2da8b71 100644 --- a/bog.el +++ b/bog.el @@ -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) -- cgit v1.2.3