diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2021-01-20 04:44:18 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-01-20 04:44:18 +0100 |
commit | 40a5df81434ce02fba01779256b50976fb74da4f (patch) | |
tree | 706991cdbf784b269a206df7202cf6bf5b0503db | |
parent | 3bbec2eb2b2a48a0eaac8e83c27313bfbe9d420e (diff) | |
download | emacs-40a5df81434ce02fba01779256b50976fb74da4f.tar.gz |
Make `symbol-at-point' work in buffers with no symbols
* lisp/thingatpt.el (thing-at-point--end-of-symbol): New function
(bug#14234).
(symbol): Use it instead of `forward-symbol', because the latter
will move to the end of the buffer even if there is no symbol
there. Instead error out like `forward-sexp' and friends.
-rw-r--r-- | lisp/thingatpt.el | 8 | ||||
-rw-r--r-- | test/lisp/thingatpt-tests.el | 14 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index d3ba941fcc2..69c23c35431 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el @@ -218,6 +218,14 @@ The bounds of THING are determined by `bounds-of-thing-at-point'." (put 'sexp 'beginning-op 'thing-at-point--beginning-of-sexp) +;; Symbols + +(put 'symbol 'end-op 'thing-at-point--end-of-symbol) + +(defun thing-at-point--end-of-symbol () + "Move point to the end of the current symbol." + (re-search-forward "\\(\\sw\\|\\s_\\)+")) + ;; Lists (put 'list 'bounds-of-thing-at-point 'thing-at-point-bounds-of-list-at-point) diff --git a/test/lisp/thingatpt-tests.el b/test/lisp/thingatpt-tests.el index c43c81af9fd..b7c315062f9 100644 --- a/test/lisp/thingatpt-tests.el +++ b/test/lisp/thingatpt-tests.el @@ -146,4 +146,18 @@ position to retrieve THING.") (should (thing-at-point-looking-at "2abcd")) (should (equal (match-data) m2))))) +(ert-deftest test-narrow-buffer-symbol () + (with-temp-buffer + (insert "foo bar zot") + (goto-char 5) + (should (equal (symbol-at-point) 'bar))) + (with-temp-buffer + (insert "`[[`(") + (goto-char 2) + (should (equal (symbol-at-point) nil))) + (with-temp-buffer + (insert "aa `[[`(") + (goto-char 4) + (should (equal (symbol-at-point) nil)))) + ;;; thingatpt.el ends here |