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/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 e079a84d..3eeeb298 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). @@ -217,13 +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 (nth 4 ppss)) (nth 8 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 @@ -253,7 +252,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 +294,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))) @@ -518,17 +520,19 @@ just return nil." (forward-line 1))))) (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)))))) + "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 (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 (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)) @@ -547,29 +551,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 diff --git a/elixir-smie.el b/elixir-smie.el index 78344c97..96f7a2d6 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))) @@ -187,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\\)"))) @@ -260,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 () @@ -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))))) @@ -876,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 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)