From ff18658bfab3ab31947282bd1bc7ce1510c38286 Mon Sep 17 00:00:00 2001 From: Ivan Sokolov Date: Fri, 7 May 2021 09:23:41 +0300 Subject: [PATCH 1/5] Replace set+make-local-variable with setq-local --- elixir-mode.el | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/elixir-mode.el b/elixir-mode.el index e079a84d..3320d7cc 100644 --- a/elixir-mode.el +++ b/elixir-mode.el @@ -547,29 +547,27 @@ just return nil." "Major mode for editing Elixir code. \\{elixir-mode-map}" - (set (make-local-variable 'font-lock-defaults) - '(elixir-font-lock-keywords - nil nil nil nil - (font-lock-syntactic-face-function - . elixir-font-lock-syntactic-face-function))) - (set (make-local-variable 'comment-start) "# ") - (set (make-local-variable 'comment-end) "") - (set (make-local-variable 'comment-start-skip) "#+ *") - (set (make-local-variable 'comment-use-syntax) t) - (set (make-local-variable 'syntax-propertize-function) - #'elixir-syntax-propertize-function) - (set (make-local-variable 'imenu-generic-expression) - elixir-imenu-generic-expression) - - (set (make-local-variable 'beginning-of-defun-function) #'elixir-beginning-of-defun) - (set (make-local-variable 'end-of-defun-function) #'elixir-end-of-defun) + (setq-local font-lock-defaults + '(elixir-font-lock-keywords + nil nil nil nil + (font-lock-syntactic-face-function + . elixir-font-lock-syntactic-face-function))) + (setq-local comment-start "# ") + (setq-local comment-end "") + (setq-local comment-start-skip "#+ *") + (setq-local comment-use-syntax t) + (setq-local syntax-propertize-function #'elixir-syntax-propertize-function) + (setq-local imenu-generic-expression elixir-imenu-generic-expression) + + (setq-local beginning-of-defun-function #'elixir-beginning-of-defun) + (setq-local end-of-defun-function #'elixir-end-of-defun) (smie-setup elixir-smie-grammar 'verbose-elixir-smie-rules :forward-token 'elixir-smie-forward-token :backward-token 'elixir-smie-backward-token) ;; https://github.com/elixir-editors/emacs-elixir/issues/363 ;; http://debbugs.gnu.org/cgi/bugreport.cgi?bug=35496 - (set (make-local-variable 'smie-blink-matching-inners) nil)) + (setq-local smie-blink-matching-inners nil)) ;; Invoke elixir-mode when appropriate From 06abc4d84a2be36d872f897fdba257eb0ae2636c Mon Sep 17 00:00:00 2001 From: Ivan Sokolov Date: Fri, 7 May 2021 10:01:46 +0300 Subject: [PATCH 2/5] Backport ppss accessors --- elixir-mode.el | 19 +++++++++++------ elixir-smie.el | 58 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/elixir-mode.el b/elixir-mode.el index 3320d7cc..b7d9f215 100644 --- a/elixir-mode.el +++ b/elixir-mode.el @@ -200,7 +200,7 @@ (rx-to-string (car sexps) t)))))) (defsubst elixir-syntax-in-string-or-comment-p () - (nth 8 (syntax-ppss))) + (elixir-ppss-comment-or-string-start (syntax-ppss))) (defsubst elixir-syntax-count-quotes (quote-char &optional point limit) "Count number of quotes around point (max is 3). @@ -221,7 +221,8 @@ is used to limit the scan." (backward-char num-quotes) (syntax-ppss) (forward-char num-quotes))) - (string-start (and (not (nth 4 ppss)) (nth 8 ppss))) + (string-start (and (not (elixir-ppss-comment-depth ppss)) + (elixir-ppss-comment-or-string-start ppss))) (quote-starting-pos (- (point) num-quotes)) (quote-ending-pos (point)) (num-closing-quotes @@ -253,7 +254,8 @@ is used to limit the scan." (context (save-excursion (save-match-data (syntax-ppss beg))))) (put-text-property beg (1+ beg) 'syntax-table (string-to-syntax "w")) (put-text-property beg (1+ beg) 'elixir-interpolation - (cons (nth 3 context) (match-data))))) + (cons (elixir-ppss-string-terminator context) + (match-data))))) (defconst elixir-sigil-delimiter-pair '((?\( . ")") @@ -294,7 +296,9 @@ is used to limit the scan." (funcall (syntax-propertize-rules ("\\(\\?\\)[\"']" - (1 (if (save-excursion (nth 3 (syntax-ppss (match-beginning 0)))) + (1 (if (save-excursion + (elixir-ppss-string-terminator + (syntax-ppss (match-beginning 0)))) ;; Within a string, skip. (ignore (goto-char (match-end 1))) @@ -519,7 +523,8 @@ just return nil." (defun elixir--docstring-p (&optional pos) "Check to see if there is a docstring at pos." - (let ((pos (or pos (nth 8 (parse-partial-sexp (point-min) (point)))))) + (let ((pos (or pos (elixir-ppss-comment-or-string-start + (parse-partial-sexp (point-min) (point)))))) (when pos (save-excursion (goto-char pos) @@ -527,8 +532,8 @@ just return nil." (line-beginning-position))))))) (defun elixir-font-lock-syntactic-face-function (state) - (if (nth 3 state) - (if (elixir--docstring-p (nth 8 state)) + (if (elixir-ppss-string-terminator state) + (if (elixir--docstring-p (elixir-ppss-comment-or-string-start state)) font-lock-doc-face font-lock-string-face) font-lock-comment-face)) diff --git a/elixir-smie.el b/elixir-smie.el index 78344c97..508d8c95 100644 --- a/elixir-smie.el +++ b/elixir-smie.el @@ -67,6 +67,38 @@ (rassoc next smie-closer-alist)))) (smie-indent-calculate)))))))) +;; In Emacs 27, ppss became a structure and has proper accessors. + +(defalias 'elixir-ppss-depth + (if (<= 27 emacs-major-version) + 'ppss-depth + (lambda (parse-data) (nth 0 parse-data)))) + +(defalias 'elixir-ppss-innermost-start + (if (<= 27 emacs-major-version) + 'ppss-innermost-start + (lambda (parse-data) (nth 1 parse-data)))) + +(defalias 'elixir-ppss-last-complete-sexp-start + (if (<= 27 emacs-major-version) + 'ppss-last-complete-sexp-start + (lambda (parse-data) (nth 2 parse-data)))) + +(defalias 'elixir-ppss-string-terminator + (if (<= 27 emacs-major-version) + 'ppss-string-terminator + (lambda (parse-data) (nth 3 parse-data)))) + +(defalias 'elixir-ppss-comment-depth + (if (<= 27 emacs-major-version) + 'ppss-comment-depth + (lambda (parse-data) (nth 4 parse-data)))) + +(defalias 'elixir-ppss-comment-or-string-start + (if (<= 27 emacs-major-version) + 'ppss-comment-or-string-start + (lambda (parse-data) (nth 8 parse-data)))) + (defun elixir-smie-looking-around (back at) "Check if looking backwards at BACK and forward at AT." (and (looking-at-p at) (looking-back back))) @@ -279,7 +311,7 @@ (if (elixir-smie--semi-ends-match) "MATCH-STATEMENT-DELIMITER" (if (and (looking-at ".+,$") - (not (> (nth 0 (syntax-ppss)) 0))) + (not (> (elixir-ppss-depth (syntax-ppss)) 0))) "COMMA" ";"))) ((looking-at elixir-smie--block-operator-regexp) @@ -308,7 +340,7 @@ (if (elixir-smie--semi-ends-match) "MATCH-STATEMENT-DELIMITER" (if (and (looking-back ",$" (- (point) 3) t) - (not (> (nth 0 (syntax-ppss)) 0))) + (not (> (elixir-ppss-depth (syntax-ppss)) 0))) "COMMA" ";"))) ((looking-back elixir-smie--block-operator-regexp (- (point) 3) t) @@ -446,11 +478,11 @@ (not (smie-rule-hanging-p))) 0) ((and (not (smie-rule-sibling-p)) - (nth 2 smie--parent) + (elixir-ppss-last-complete-sexp-start smie--parent) (smie-rule-hanging-p)) (smie-rule-parent elixir-smie-indent-basic)) ((and (not (smie-rule-sibling-p)) - (not (nth 2 smie--parent)) + (not (elixir-ppss-last-complete-sexp-start smie--parent)) (smie-rule-hanging-p)) (smie-rule-parent)))) (`(:after . "MATCH-STATEMENT-DELIMITER") @@ -512,12 +544,12 @@ (save-excursion (move-beginning-of-line 1) (looking-at "^\s*do:.+$"))) - (if (> (nth 0 (syntax-ppss)) 0) + (if (> (elixir-ppss-depth (syntax-ppss)) 0) (smie-rule-parent (- 3)) (smie-rule-parent elixir-smie-indent-basic))) ((and (smie-rule-parent-p ";") (not (smie-rule-hanging-p))) - (if (> (nth 0 (syntax-ppss)) 0) + (if (> (elixir-ppss-depth (syntax-ppss)) 0) (smie-rule-parent (- elixir-smie-indent-basic)) (smie-rule-parent))) ((and (smie-rule-parent-p "OP") @@ -567,7 +599,7 @@ (`(:before . "else:") (cond ((smie-rule-parent-p ";") - (if (> (nth 0 (syntax-ppss)) 0) + (if (> (elixir-ppss-depth (syntax-ppss)) 0) (smie-rule-parent elixir-smie-indent-basic) (smie-rule-parent))) ((smie-rule-parent-p "if") @@ -724,7 +756,7 @@ ;; ... then indent the line after the `->' aligned with the ;; parent, offset by `elixir-smie-indent-basic'." (if (and smie--parent (elixir-smie--same-line-as-parent - (nth 1 smie--parent) + (elixir-ppss-innermost-start smie--parent) (point))) (smie-rule-parent elixir-smie-indent-basic) elixir-smie-indent-basic)) @@ -845,12 +877,10 @@ (defun elixir-smie--heredoc-at-current-point-p () "Return non-nil if cursor is at a string." (save-excursion - (or (and (nth 3 (save-excursion - (let ((pos (point))) - (parse-partial-sexp 1 pos)))) - (nth 8 (save-excursion - (let ((pos (point))) - (parse-partial-sexp 1 pos))))) + (or (save-excursion + (let ((parse-data (parse-partial-sexp 1 (point)))) + (and (elixir-ppss-string-terminator parse-data) + (elixir-ppss-comment-or-string-start parse-data)))) (and (looking-at "\"\"\"") (match-beginning 0))))) From f63599eaf0e223ca4975bd7cb375da54df6f6ab7 Mon Sep 17 00:00:00 2001 From: Ivan Sokolov Date: Fri, 7 May 2021 10:16:04 +0300 Subject: [PATCH 3/5] Fix formatting, use save-excursion instead of saving point manually --- elixir-mode.el | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/elixir-mode.el b/elixir-mode.el index b7d9f215..64e0ac6b 100644 --- a/elixir-mode.el +++ b/elixir-mode.el @@ -217,14 +217,12 @@ is used to limit the scan." (defun elixir-syntax-stringify () "Put `syntax-table' property correctly on single/triple quotes." (let* ((num-quotes (length (match-string-no-properties 1))) - (ppss (prog2 - (backward-char num-quotes) - (syntax-ppss) - (forward-char num-quotes))) - (string-start (and (not (elixir-ppss-comment-depth ppss)) - (elixir-ppss-comment-or-string-start ppss))) (quote-starting-pos (- (point) num-quotes)) (quote-ending-pos (point)) + (ppss (save-excursion + (syntax-ppss quote-starting-pos))) + (string-start (and (not (elixir-ppss-comment-depth ppss)) + (elixir-ppss-comment-or-string-start ppss))) (num-closing-quotes (and string-start (elixir-syntax-count-quotes @@ -528,8 +526,9 @@ just return nil." (when pos (save-excursion (goto-char pos) - (and (looking-at "\"\"\"")(looking-back (rx "@" (or "moduledoc" "typedoc" "doc") (+ space)) - (line-beginning-position))))))) + (and (looking-at "\"\"\"") + (looking-back (rx "@" (or "moduledoc" "typedoc" "doc") (+ space)) + (line-beginning-position))))))) (defun elixir-font-lock-syntactic-face-function (state) (if (elixir-ppss-string-terminator state) From a1e9cf6d8ec17cb97c7bddbfd0d2414a4ba6cfa3 Mon Sep 17 00:00:00 2001 From: Ivan Sokolov Date: Fri, 7 May 2021 10:18:16 +0300 Subject: [PATCH 4/5] Fix docstring formatting --- elixir-format.el | 2 +- elixir-mode.el | 2 +- elixir-smie.el | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/elixir-format.el b/elixir-format.el index 6c2ab224..71940c56 100644 --- a/elixir-format.el +++ b/elixir-format.el @@ -26,7 +26,7 @@ (require 'ansi-color) (defcustom elixir-format-arguments nil - "Additional arguments to 'mix format'" + "Additional arguments to 'mix format'." :type '(repeat string) :group 'elixir :group 'elixir-format) diff --git a/elixir-mode.el b/elixir-mode.el index 64e0ac6b..3eeeb298 100644 --- a/elixir-mode.el +++ b/elixir-mode.el @@ -520,7 +520,7 @@ just return nil." (forward-line 1))))) (defun elixir--docstring-p (&optional pos) - "Check to see if there is a docstring at pos." + "Check to see if there is a docstring at POS." (let ((pos (or pos (elixir-ppss-comment-or-string-start (parse-partial-sexp (point-min) (point)))))) (when pos diff --git a/elixir-smie.el b/elixir-smie.el index 508d8c95..96f7a2d6 100644 --- a/elixir-smie.el +++ b/elixir-smie.el @@ -219,7 +219,7 @@ (looking-back elixir-smie--operator-regexp (- (point) 3) t)))) (defun elixir-smie-current-line-contains-built-in-keyword-p () - "Return non-nil if the current line contains built in keywords with a `.'" + "Return non-nil if the current line contains built in keywords with a \".\"." (save-excursion (beginning-of-line) (looking-at ".+\\.\\(case\\|try\\|if\\|rescue\\)"))) @@ -292,7 +292,7 @@ (not (looking-back ".+fn.+"))))))))) (defun elixir-smie--same-line-as-parent (parent-pos child-pos) - "Return non-nil if `child-pos' is on same line as `parent-pos'." + "Return non-nil if CHILD-POS is on same line as PARENT-POS." (= (line-number-at-pos parent-pos) (line-number-at-pos child-pos))) (defun elixir-smie-forward-token () @@ -906,8 +906,7 @@ Rules: 1. If the previous line is empty, indent as the basic indentation at the beginning of the heredoc. - 2. If the previous line is not empty, indent as the previous line. -" + 2. If the previous line is not empty, indent as the previous line." (if (eq major-mode 'elixir-mode) (if (elixir-smie--heredoc-at-current-point-p) (let ((indent From bbe0e278a98076d9dfb798ca1f2b01948b707c35 Mon Sep 17 00:00:00 2001 From: Ivan Sokolov Date: Fri, 7 May 2021 10:24:50 +0300 Subject: [PATCH 5/5] Remove s --- Eldev | 2 -- tests/test-helper.el | 1 - 2 files changed, 3 deletions(-) diff --git a/Eldev b/Eldev index 0e7f75aa..17626d60 100644 --- a/Eldev +++ b/Eldev @@ -7,5 +7,3 @@ (eldev-use-plugin 'undercover) (eldev-add-loading-roots 'test "tests") - -(eldev-add-extra-dependencies 'test 's) diff --git a/tests/test-helper.el b/tests/test-helper.el index 6af0d0a9..11b31f2b 100644 --- a/tests/test-helper.el +++ b/tests/test-helper.el @@ -7,7 +7,6 @@ (require 'ert-x) ; `ert-with-test-buffer' (require 'cl-lib) ; `cl-defmacro' -(require 's) (message "Running tests on Emacs %s" emacs-version)