diff options
| author | Visuwesh | 2024-03-09 15:17:26 +0530 |
|---|---|---|
| committer | Eli Zaretskii | 2024-03-14 11:39:33 +0200 |
| commit | cb9ee24ea69be4a70f68cb2d564b23a55cb84216 (patch) | |
| tree | 9ef3b7132e1e739de158d2ae40f99b8014d88eb9 | |
| parent | a60804ab954e0de73a80a217f677142176678465 (diff) | |
| download | emacs-cb9ee24ea69be4a70f68cb2d564b23a55cb84216.tar.gz emacs-cb9ee24ea69be4a70f68cb2d564b23a55cb84216.zip | |
Add bounds-of-thing-at-point property for 'number'
* lisp/thingatpt.el (thing-at-point-decimal-regexp)
(thing-at-point-hexadecimal-regexp): Extract regexps from...
(number-at-point): ...here. Use them in 'number-at-point'.
(number): Add 'bounds-of-thing-at-point' property as
`forward-word' does not always return the right boundary,
e.g., in latex-mode buffers. (Bug#69239)
| -rw-r--r-- | lisp/thingatpt.el | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index 83ddc640d35..7896ad984df 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el | |||
| @@ -735,20 +735,33 @@ Signal an error if the entire string was not used." | |||
| 735 | (let ((thing (thing-at-point 'symbol))) | 735 | (let ((thing (thing-at-point 'symbol))) |
| 736 | (if thing (intern thing)))) | 736 | (if thing (intern thing)))) |
| 737 | 737 | ||
| 738 | (defvar thing-at-point-decimal-regexp | ||
| 739 | "-?[0-9]+\\.?[0-9]*" | ||
| 740 | "A regexp matching a decimal number.") | ||
| 741 | |||
| 742 | (defvar thing-at-point-hexadecimal-regexp | ||
| 743 | "\\(0x\\|#x\\)\\([a-fA-F0-9]+\\)" | ||
| 744 | "A regexp matchin a hexadecimal number.") | ||
| 745 | |||
| 738 | ;;;###autoload | 746 | ;;;###autoload |
| 739 | (defun number-at-point () | 747 | (defun number-at-point () |
| 740 | "Return the number at point, or nil if none is found. | 748 | "Return the number at point, or nil if none is found. |
| 741 | Decimal numbers like \"14\" or \"-14.5\", as well as hex numbers | 749 | Decimal numbers like \"14\" or \"-14.5\", as well as hex numbers |
| 742 | like \"0xBEEF09\" or \"#xBEEF09\", are recognized." | 750 | like \"0xBEEF09\" or \"#xBEEF09\", are recognized." |
| 743 | (cond | 751 | (cond |
| 744 | ((thing-at-point-looking-at "\\(0x\\|#x\\)\\([a-fA-F0-9]+\\)" 500) | 752 | ((thing-at-point-looking-at thing-at-point-hexadecimal-regexp 500) |
| 745 | (string-to-number | 753 | (string-to-number |
| 746 | (buffer-substring (match-beginning 2) (match-end 2)) | 754 | (buffer-substring (match-beginning 2) (match-end 2)) |
| 747 | 16)) | 755 | 16)) |
| 748 | ((thing-at-point-looking-at "-?[0-9]+\\.?[0-9]*" 500) | 756 | ((thing-at-point-looking-at thing-at-point-decimal-regexp 500) |
| 749 | (string-to-number | 757 | (string-to-number |
| 750 | (buffer-substring (match-beginning 0) (match-end 0)))))) | 758 | (buffer-substring (match-beginning 0) (match-end 0)))))) |
| 751 | 759 | ||
| 760 | (put 'number 'bounds-of-thing-at-point | ||
| 761 | (lambda () | ||
| 762 | (and (or (thing-at-point-looking-at thing-at-point-hexadecimal-regexp 500) | ||
| 763 | (thing-at-point-looking-at thing-at-point-decimal-regexp 500)) | ||
| 764 | (cons (match-beginning 0) (match-end 0))))) | ||
| 752 | (put 'number 'forward-op 'forward-word) | 765 | (put 'number 'forward-op 'forward-word) |
| 753 | (put 'number 'thing-at-point 'number-at-point) | 766 | (put 'number 'thing-at-point 'number-at-point) |
| 754 | 767 | ||