emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/smalltalk-mode a83f2e1: * smalltalk-mode.el: Mark <foo:


From: Stefan Monnier
Subject: [elpa] externals/smalltalk-mode a83f2e1: * smalltalk-mode.el: Mark <foo: 'bar'> pragmas as parenthesized
Date: Mon, 15 Apr 2019 15:05:24 -0400 (EDT)

branch: externals/smalltalk-mode
commit a83f2e118a23eed66aab53478e53fde810945650
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    * smalltalk-mode.el: Mark <foo: 'bar'> pragmas as parenthesized
    
    (smalltalk--pragma-start-p, smalltalk--pragma-end-p): New functions.
    (smalltalk--syntax-propertize): Use them.
---
 smalltalk-mode.el | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/smalltalk-mode.el b/smalltalk-mode.el
index 043edf5..bb0861a 100644
--- a/smalltalk-mode.el
+++ b/smalltalk-mode.el
@@ -218,13 +218,39 @@
     ;; in case we use the compiled file on a newer Emacs.
     `(eval '(if (fboundp ',sym) ,exp))))
 
+(defun smalltalk--pragma-start-p (pos)
+  ;; I think in practice it's not disastrous if we fail to mark some pragmas,
+  ;; whereas if we mistakenly mark a binary `<' as an open-paren, this
+  ;; can throw things off pretty badly, so when in doubt presume it's just
+  ;; a binary `<'.
+  (save-excursion
+    (goto-char pos)
+    (forward-comment (- (point)))
+    (pcase (char-before)
+      ((or `nil `?\[) t)
+      (`?> (and (< (point) pos)      ;; >< is a binary selector
+                (equal (syntax-after (1- (point)))
+                       (string-to-syntax ")<")))))))
+
+
+(defun smalltalk--pragma-end-p (pos)
+  (save-excursion
+    (let ((ppss (syntax-ppss pos)))
+      (and (nth 1 ppss)
+           (eq ?< (char-after (nth 1 ppss)))))))
+
 (defconst smalltalk--syntax-propertize
   (smalltalk--when-fboundp syntax-propertize-rules
     (syntax-propertize-rules
      ;; $ is marked as escaping because it can escape a ' or a " when
      ;; used for a character literal, but not when used within strings.
      ("\\(\\$\\)[][(){}'\")]"
-      (1 (if (nth 8 (syntax-ppss)) (string-to-syntax ".")))))))
+      (1 (if (nth 8 (syntax-ppss)) (string-to-syntax "."))))
+     ("<" (0 (if (smalltalk--pragma-start-p (match-beginning 0))
+                 (string-to-syntax "(>"))))
+     (">" (0 (if (smalltalk--pragma-end-p (match-beginning 0))
+                 (string-to-syntax ")<"))))
+     )))
 
 ;;;; ---[ SMIE support ]------------------------------------------------
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]