[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] externals/caml bce861f 181/197: Emacs: Use built-in detection o
From: |
Stefan Monnier |
Subject: |
[nongnu] externals/caml bce861f 181/197: Emacs: Use built-in detection of comments |
Date: |
Sat, 21 Nov 2020 01:20:03 -0500 (EST) |
branch: externals/caml
commit bce861f61923e49744d2f79ac6866dcfe417f10e
Author: Wilfred Hughes <wilfred@fb.com>
Commit: Wilfred Hughes <wilfred@fb.com>
Emacs: Use built-in detection of comments
This fixes
https://caml.inria.fr/mantis/view.php?id=7844
where we crashed if we found text that looked like a definition inside
a comment.
This is also faster and simpler. Emacs does handle nested comments
correctly, but the comments worrying about this were written in 1996
when that may have been true.
---
caml.el | 92 +----------------------------------------------------------------
1 file changed, 1 insertion(+), 91 deletions(-)
diff --git a/caml.el b/caml.el
index 1945fba..8204d5e 100644
--- a/caml.el
+++ b/caml.el
@@ -456,25 +456,6 @@ have caml-electric-indent on, which see.")
;; Other internal variables
-(defvar caml-last-noncomment-pos nil
- "Caches last buffer position determined not inside a caml comment.")
-(make-variable-buffer-local 'caml-last-noncomment-pos)
-
-;;last-noncomment-pos can be a simple position, because we nil it
-;;anyway whenever buffer changes upstream. last-comment-start and -end
-;;have to be markers, because we preserve them when the changes' end
-;;doesn't overlap with the comment's start.
-
-(defvar caml-last-comment-start nil
- "A marker caching last determined caml comment start.")
-(make-variable-buffer-local 'caml-last-comment-start)
-
-(defvar caml-last-comment-end nil
- "A marker caching last determined caml comment end.")
-(make-variable-buffer-local 'caml-last-comment-end)
-
-(make-variable-buffer-local 'before-change-function)
-
(defvar caml-imenu-shown nil
"True if we have computed definition list.")
(make-variable-buffer-local 'caml-imenu-shown)
@@ -531,11 +512,6 @@ have caml-electric-indent on, which see.")
;itz Fri Sep 25 13:23:49 PDT 1998
(make-local-variable 'add-log-current-defun-function)
(setq add-log-current-defun-function 'caml-current-defun)
- ;itz 03-25-96
- (setq before-change-function 'caml-before-change-function)
- (setq caml-last-noncomment-pos nil)
- (setq caml-last-comment-start (make-marker))
- (setq caml-last-comment-end (make-marker))
;garrigue 27-11-96
(setq case-fold-search nil)
;garrigue july 97
@@ -1058,22 +1034,6 @@ to the end.
(defun caml-overlap (b1 e1 b2 e2)
(<= (max b1 b2) (min e1 e2)))
-;this clears the last comment cache if necessary
-(defun caml-before-change-function (begin end)
- (if (and caml-last-noncomment-pos
- (> caml-last-noncomment-pos begin))
- (setq caml-last-noncomment-pos nil))
- (if (and (marker-position caml-last-comment-start)
- (marker-position caml-last-comment-end)
- (caml-overlap begin end
- caml-last-comment-start
- caml-last-comment-end))
- (prog2
- (set-marker caml-last-comment-start nil)
- (set-marker caml-last-comment-end nil)))
- (let ((orig-function (default-value 'before-change-function)))
- (if orig-function (funcall orig-function begin end))))
-
(defun caml-in-literal-p ()
"Returns non-nil if point is inside a caml literal."
(let* ((start-literal (concat "[\"" caml-quote-char "]"))
@@ -1137,57 +1097,7 @@ to the end.
(defun caml-in-comment-p ()
"Returns non-nil if point is inside a caml comment.
Returns nil for the parenthesis opening a comment."
- ;;we look for comments differently than literals. there are two
- ;;reasons for this. first, caml has nested comments and it is not so
- ;;clear that parse-partial-sexp supports them; second, if proper
- ;;style is used, literals are never split across lines, so we don't
- ;;have to worry about bogus phrase breaks inside literals, while we
- ;;have to account for that possibility in comments.
- (if caml-last-comment-start
- (save-excursion
- (let* ((cached-pos caml-last-noncomment-pos)
- (cached-begin (marker-position caml-last-comment-start))
- (cached-end (marker-position caml-last-comment-end)))
- (cond
- ((and cached-begin cached-end
- (< cached-begin (point)) (< (point) cached-end)) t)
- ((and cached-pos (= cached-pos (point))) nil)
- ((and cached-pos (> cached-pos (point))
- (< (abs (- cached-pos (point))) caml-lookback-limit))
- (let (end found (here (point)))
- ; go back to somewhere sure
- (goto-char cached-pos)
- (while (> (point) here)
- ; look for the end of a comment
- (while (and (if (search-backward comment-end (1- here) 'move)
- (setq end (match-end 0))
- (setq end nil))
- (caml-in-literal-p)))
- (if end (setq found (caml-backward-comment))))
- (if (and found (= (point) here)) (setq end nil))
- (if (not end)
- (setq caml-last-noncomment-pos here)
- (set-marker caml-last-comment-start (point))
- (set-marker caml-last-comment-end end))
- end))
- (t
- (let (begin found (here (point)))
- ;; go back to somewhere sure (or far enough)
- (goto-char
- (if cached-pos cached-pos (- (point) caml-lookback-limit)))
- (while (< (point) here)
- ;; look for the beginning of a comment
- (while (and (if (search-forward comment-start (1+ here) 'move)
- (setq begin (match-beginning 0))
- (setq begin nil))
- (caml-in-literal-p)))
- (if begin (setq found (caml-forward-comment))))
- (if (and found (= (point) here)) (setq begin nil))
- (if (not begin)
- (setq caml-last-noncomment-pos here)
- (set-marker caml-last-comment-start begin)
- (set-marker caml-last-comment-end (point)))
- begin)))))))
+ (nth 4 (syntax-ppss)))
;; Various constants and regexps
- [nongnu] externals/caml 6e0e050 134/197: PR#5455: .emacs instructions, add lines to recognize ocaml scripts, (continued)
- [nongnu] externals/caml 6e0e050 134/197: PR#5455: .emacs instructions, add lines to recognize ocaml scripts, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml 56e93b6 151/197: fix a few problems with whitespace and over-long lines, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml f4c7308 168/197: caml.el: Reduce byte-compilation warnings, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml a0d389f 058/197: skip structs in let module ... in, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml 442bd24 059/197: prepare snapshot, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml ac2a0b2 064/197: ajout option -stypes; depend, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml faa1c81 065/197: ajout choses a faire, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml 76f4e2b 116/197: amelioration des annotations, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml 64cecd3 128/197: merge changes from 3.12.0 to 3.12.1, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml 64a3c02 166/197: Fixing some Emacs startup warnings., Stefan Monnier, 2020/11/21
- [nongnu] externals/caml bce861f 181/197: Emacs: Use built-in detection of comments,
Stefan Monnier <=
- [nongnu] externals/caml ac5d007 047/197: caml-indent-phrase, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml 3d7f47c 066/197: amelioration .mly .mll, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml 099dbf5 067/197: -stypes -> -dtypes; meilleur mode emacs, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml 1991236 046/197: improve indentation, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml 5ac4447 133/197: correct syntax highlighting in emacs (continued), Stefan Monnier, 2020/11/21
- [nongnu] externals/caml 6084272 137/197: PR#5176: caml-types.el: large types trigger stack overflow in regexp matcher, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml 0ca1e97 155/197: Merge branch 4.01 from branching point to 4.01.0+rc1, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml d7a872b 170/197: caml.el: update authors list, Stefan Monnier, 2020/11/21
- [nongnu] externals/caml ae92bb1 173/197: Fix emacs mode (raise/failwith/invalid_arg regexp)., Stefan Monnier, 2020/11/21
- [nongnu] externals/caml d8a2f7d 165/197: caml-types.el: Fix missing format argument, Stefan Monnier, 2020/11/21