[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/smalltalk-mode 626f6b8: * smalltalk-mode.el (smalltalk-
From: |
Stefan Monnier |
Subject: |
[elpa] externals/smalltalk-mode 626f6b8: * smalltalk-mode.el (smalltalk-use-smie): Use SMIE by default |
Date: |
Mon, 22 Apr 2019 00:54:24 -0400 (EDT) |
branch: externals/smalltalk-mode
commit 626f6b8c99894855e6af09fcdc48d44e8a7cf0f9
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>
* smalltalk-mode.el (smalltalk-use-smie): Use SMIE by default
(smalltalk-mode-map): Use SMIE's C-M-f and C-M-b when available.
(smalltalk--definition-pos-p): Comment-out.
(smalltalk--syntax-propertize): Mark the \n between "scopes".
(smalltalk--smie-rules): Remove the hack for "definitions" since they're
now handled properly thanks to the \n separator.
Only indent after the "\n" of a gst2-style method header.
(smalltalk--smie-grammar): Remove the "id" from `id` now that don't
need to invoke smie-rules for it.
---
smalltalk-mode.el | 81 ++++++++++++++++++++++++++++++++-----------------------
1 file changed, 48 insertions(+), 33 deletions(-)
diff --git a/smalltalk-mode.el b/smalltalk-mode.el
index 2a09c30..60cd571 100644
--- a/smalltalk-mode.el
+++ b/smalltalk-mode.el
@@ -39,6 +39,8 @@
;;; Code:
+(require 'smie nil t) ;Not indispensable (yet).
+
;; ===[ Variables and constants ]=====================================
(defgroup smalltalk-mode ()
@@ -64,6 +66,11 @@
"If non-nil, try and align the `:' of keyword selectors."
:type 'boolean)
+(defcustom smalltalk-use-smie (featurep 'smie)
+ "Whether to use SMIE for indentation and navigation.
+Requires Emacsā„23.3."
+ :type 'boolean)
+
;;;; ---[ Syntax Table ]------------------------------------------------
;; This may very well be a bug, but certin chars like ?+ are set to be
@@ -149,14 +156,16 @@
;; (define-key keymap "\n" 'smalltalk-newline-and-indent)
(define-key keymap "\C-c\C-a" 'smalltalk-begin-of-defun)
(define-key keymap "\C-c\C-e" 'smalltalk-end-of-defun)
- (define-key keymap "\C-c\C-f" 'smalltalk-forward-sexp)
- (define-key keymap "\C-c\C-b" 'smalltalk-backward-sexp)
+ (unless smalltalk-use-smie
+ (define-key keymap "\C-c\C-f" 'smalltalk-forward-sexp)
+ (define-key keymap "\C-c\C-b" 'smalltalk-backward-sexp))
(define-key keymap "\C-c\C-p" 'smalltalk-goto-previous-keyword)
(define-key keymap "\C-c\C-n" 'smalltalk-goto-next-keyword)
;; the following three are deprecated
(define-key keymap "\C-\M-a" 'smalltalk-begin-of-defun)
- (define-key keymap "\C-\M-f" 'smalltalk-forward-sexp)
- (define-key keymap "\C-\M-b" 'smalltalk-backward-sexp)
+ (unless smalltalk-use-smie
+ (define-key keymap "\C-\M-f" 'smalltalk-forward-sexp)
+ (define-key keymap "\C-\M-b" 'smalltalk-backward-sexp))
;; FIXME: Use post-self-insert-hook!
(define-key keymap "!" 'smalltalk-bang)
;; FIXME: Use post-self-insert-hook!
@@ -185,16 +194,16 @@
(defconst smalltalk-binsel "[-+*/~,<>=&?]\\{1,2\\}\\|\\(:=\\)\\|||"
"Smalltalk binary selectors.")
-(defun smalltalk--definition-pos-p ()
- ;; In the non-bang style, we consider that a selector is in a "definition
- ;; position" (i.e. is defined rather than used to call a method) if it
- ;; follows a [...] that's not a block.
- ;; FIXME: This fails to accept the *first* definition in a list.
- (save-excursion
- (forward-comment (- (point)))
- (when (eq (char-before) ?\])
- (forward-sexp -1)
- (not (smalltalk--smie-exp-p)))))
+;; (defun smalltalk--definition-pos-p ()
+;; ;; In the non-bang style, we consider that a selector is in a "definition
+;; ;; position" (i.e. is defined rather than used to call a method) if it
+;; ;; follows a [...] that's not a block.
+;; ;; FIXME: This fails to accept the *first* definition in a list.
+;; (save-excursion
+;; (forward-comment (- (point)))
+;; (when (eq (char-before) ?\])
+;; (forward-sexp -1)
+;; (not (smalltalk--smie-exp-p)))))
(defconst smalltalk-font-lock-keywords
`((,(concat "#" smalltalk-name-regexp) (0 'font-lock-constant-face))
@@ -275,6 +284,17 @@
;; FIXME: Ugly Hack! Mark the newline typically placed
;; after the method header as a separator in the "gst2-aka-bang" syntax.
("![ \t\n]*\n[[:lower:]][[:alnum:]_:. \t]*\\(\n\\)" (1 "."))
+ ;; Similarly to the previous one, mark the \n after the `]' closing
+ ;; a "scope".
+ ;; FIXME: This presumes there is a \n after the `]' and there's no comment
+ ;; or other funny business between the two.
+ ("][ \t]*\\(\n\\)"
+ (1 (save-excursion
+ (let ((ppss (syntax-ppss (match-beginning 0))))
+ (when (nth 1 ppss)
+ (goto-char (nth 1 ppss))
+ (unless (smalltalk--smie-exp-p)
+ (string-to-syntax ".")))))))
)))
;;;; ---[ SMIE support ]------------------------------------------------
@@ -282,12 +302,6 @@
;; FIXME: This is still rough around the edges, but is fairly usable
;; in non-bang-style files. About as good as the old indentation code now.
-(defvar smalltalk-use-smie nil
- "Whether to use SMIE for indentation and navigation.
-The SMIE support is currently experimental work-in-progress.")
-
-(require 'smie nil t)
-
(defvar smalltalk--smie-grammar
;; The "bang syntax" is described at
;; https://www.gnu.org/software/smalltalk/manual/html_node/The-syntax.html
@@ -308,7 +322,7 @@ The SMIE support is currently experimental
work-in-progress.")
(when (fboundp 'smie-bnf->prec2)
(smie-prec2->grammar
(smie-bnf->prec2
- '((id ("id"))
+ '((id ) ;("id")
(blockbody (id "|" exp) ;Block with args
(exp)) ;Block without args
(exp ("|-open" id "|" exp) ;Local var declaration
@@ -444,7 +458,8 @@ The SMIE support is currently experimental
work-in-progress.")
(`(:after . "|") 0)
(`(:after . ">") 0) ;Indentation after a pragma.
(`(:after . ":=") smalltalk-indent-amount)
- (`(:after . "\n") smalltalk-indent-amount) ;GST2 method header separator
+ (`(:after . "\n") (if (smie-rule-parent-p "!") ;GST2 method header
separator
+ smalltalk-indent-amount))
(`(:after . ";")
(save-excursion
(forward-char 1)
@@ -464,17 +479,17 @@ The SMIE support is currently experimental
work-in-progress.")
(`";" nil)
(_ (forward-sexp 1) (forward-comment 1)
`(column . ,(current-column)))))))
- ((and `(:before . ,(or `"kw-sel" `"bin-sel" `"id"))
- (guard (and (smie-rule-bolp)
- (smalltalk--definition-pos-p))))
- ;; Looks like a definition following another.
- ;; FIXME: While this seems to indent class/method definitions acceptably,
- ;; the underlying parsing of them is still wrong, as visible when
- ;; trying to navigate with sexp movement commands :-(
- (save-excursion
- (forward-sexp -1)
- (smalltalk--smie-begin-def)
- `(column . ,(current-column))))
+ ;; ((and `(:before . ,(or `"kw-sel" `"bin-sel" `"id"))
+ ;; (guard (and (smie-rule-bolp)
+ ;; (smalltalk--definition-pos-p))))
+ ;; ;; Looks like a definition following another.
+ ;; ;; FIXME: While this seems to indent class/method definitions
acceptably,
+ ;; ;; the underlying parsing of them is still wrong, as visible when
+ ;; ;; trying to navigate with sexp movement commands :-(
+ ;; (save-excursion
+ ;; (forward-sexp -1)
+ ;; (smalltalk--smie-begin-def)
+ ;; `(column . ,(current-column))))
(`(:before . "kw-sel")
(let ((pos (point))
(kw-len (and (looking-at smalltalk--smie-id-re)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/smalltalk-mode 626f6b8: * smalltalk-mode.el (smalltalk-use-smie): Use SMIE by default,
Stefan Monnier <=