summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bog-tests.el29
-rw-r--r--bog.el23
2 files changed, 47 insertions, 5 deletions
diff --git a/bog-tests.el b/bog-tests.el
index 6a261f4..c1c98a2 100644
--- a/bog-tests.el
+++ b/bog-tests.el
@@ -41,13 +41,40 @@
;; `bog-citekey-at-point'
-(ert-deftest bog-citekey-at-point ()
+(ert-deftest bog-citekey-at-point-bob ()
(let ((citekey "name2010word"))
(with-temp-buffer
(insert citekey)
(goto-char (point-min))
(should (equal (bog-citekey-at-point) citekey)))))
+(ert-deftest bog-citekey-at-point-newline ()
+ (let ((citekey "name2010word"))
+ (with-temp-buffer
+ (insert "\n" citekey)
+ (should (equal (bog-citekey-at-point) citekey)))))
+
+(ert-deftest bog-citekey-at-point-parens ()
+ (let ((citekey "name2010word"))
+ (with-temp-buffer
+ (insert "\n(" citekey ")")
+ (backward-char 2)
+ (should (equal (bog-citekey-at-point) citekey)))))
+
+(ert-deftest bog-citekey-at-point-spaces ()
+ (let ((citekey "name2010word"))
+ (with-temp-buffer
+ (insert "\n " citekey " ")
+ (backward-char 2)
+ (should (equal (bog-citekey-at-point) citekey)))))
+
+(ert-deftest bog-citekey-at-point-with-hyphen ()
+ (let ((citekey "hyphen-name2010word"))
+ (with-temp-buffer
+ (insert citekey)
+ (goto-char (point-min))
+ (should (equal (bog-citekey-at-point) citekey)))))
+
;; `bog-citekey-from-tree'
(ert-deftest bog-citekey-from-heading-title-current-level ()
diff --git a/bog.el b/bog.el
index 18abe4d..47d7d07 100644
--- a/bog.el
+++ b/bog.el
@@ -73,6 +73,15 @@ settings:
:group 'bog
:type 'string)
+(defcustom bog-allowed-before-citekey
+ "\\(\n\\|\\s-\\|(\\|\\[\\|{\\|<\\|,\\)"
+ "Regex that specifies characters allowed before a citekey.
+This may need to be modified if you have a custom
+`bog-citekey-format' or if you tend to used a certain character
+before citekeys that isn't included above."
+ :group 'bog
+ :type 'string)
+
(defcustom bog-citekey-property "CUSTOM_ID"
"Property name used to store citekey.
The default corresponds to the default value of
@@ -241,10 +250,16 @@ year, and the first meaningful word in the title)."
groups delim)))
(defun bog-citekey-at-point ()
- (let ((maybe-citekey (thing-at-point 'word)))
- (when (and maybe-citekey
- (bog-citekey-p maybe-citekey))
- (substring-no-properties maybe-citekey))))
+ "Return citekey at point.
+The citekey must have the format specified by
+`bog-citekey-format' and, if not at the beginning of the buffer,
+be preceded by a characters in `bog-allowed-before-citekey'."
+ (save-excursion
+ (unless (bobp)
+ (re-search-backward bog-allowed-before-citekey)
+ (forward-char 1))
+ (when (looking-at bog-citekey-format)
+ (match-string-no-properties 0))))
(defun bog-citekey-from-notes ()
"Get the citekey from the context of the Org file."