From ba20cb7cd94bc27ca0fa8e2f34443c1e122b7341 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sun, 8 Sep 2024 17:43:46 +0200 Subject: [PATCH] Drop electric-layout-mode, fix some tests --- doc/emacs/programs.texi | 6 - lisp/elec-pair.el | 15 +- lisp/electric.el | 161 +------- lisp/progmodes/js.el | 5 - lisp/progmodes/octave.el | 8 - lisp/progmodes/perl-mode.el | 1 - lisp/progmodes/project.el | 8 +- lisp/progmodes/typescript-ts-mode.el | 2 - lisp/simple.el | 4 - test/lisp/calculator-tests.el | 57 --- test/lisp/electric-tests.el | 160 +------ test/lisp/mh-e/mh-limit-tests.el | 35 -- test/lisp/mh-e/mh-thread-tests.el | 131 ------ test/lisp/mh-e/mh-utils-tests.el | 551 ------------------------- test/lisp/mh-e/mh-xface-tests.el | 50 --- test/lisp/mh-e/test-all-mh-variants.sh | 104 ----- test/lisp/simple-tests.el | 30 -- 17 files changed, 12 insertions(+), 1316 deletions(-) delete mode 100644 test/lisp/calculator-tests.el delete mode 100644 test/lisp/mh-e/mh-limit-tests.el delete mode 100644 test/lisp/mh-e/mh-thread-tests.el delete mode 100644 test/lisp/mh-e/mh-utils-tests.el delete mode 100644 test/lisp/mh-e/mh-xface-tests.el delete mode 100755 test/lisp/mh-e/test-all-mh-variants.sh diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi index 719fa93e0ad..d5be29dfd23 100644 --- a/doc/emacs/programs.texi +++ b/doc/emacs/programs.texi @@ -1843,12 +1843,6 @@ When Superword mode is enabled, the minor mode indicator appears in the mode line. See also the similar @code{subword-mode} (@pxref{MixedCase Words}). -@findex electric-layout-mode - Electric Layout mode (@kbd{M-x electric-layout-mode}) is a global -minor mode that automatically inserts newlines when you type certain -characters; for example, @samp{@{}, @samp{@}} and @samp{;} in Javascript -mode. - Apart from Hideshow mode (@pxref{Hideshow}), another way to selectively display parts of a program is to use the selective display feature (@pxref{Selective Display}). Programming modes often also diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index e952d3217fb..5627f380933 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -263,14 +263,7 @@ inside a comment or string." (defun electric-pair--insert (char times) (let ((last-command-event char) (blink-matching-paren nil) - (electric-pair-mode nil) - ;; When adding the "closer" delimiter, a job his function is - ;; frequently used for, we don't want to munch any extra - ;; newlines above us. That would be the default behavior of - ;; `electric-layout-mode', which potentially kicked in before - ;; us to add these newlines, and is probably about to kick in - ;; again after we add the closer. - (electric-layout-allow-duplicate-newlines t)) + (electric-pair-mode nil)) (self-insert-command times))) (defun electric-pair--syntax-ppss (&optional pos where) @@ -667,12 +660,6 @@ To toggle the mode in a single buffer, use `electric-pair-local-mode'." (progn (add-hook 'post-self-insert-hook #'electric-pair-post-self-insert-function - ;; Prioritize this to kick in after - ;; `electric-layout-post-self-insert-function': that - ;; considerably simplifies interoperation when - ;; `electric-pair-mode', `electric-layout-mode' and - ;; `electric-indent-mode' are used together. - ;; Use `vc-region-history' on these lines for more info. 50) (add-hook 'post-self-insert-hook #'electric-pair-open-newline-between-pairs-psif diff --git a/lisp/electric.el b/lisp/electric.el index ac597dc7bf3..6331eccaa20 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -137,18 +137,12 @@ or comment." (condition-case-unless-debug () (indent-according-to-mode) (error (throw 'indent-error nil)))) - (unless (eq electric-indent-inhibit 'electric-layout-mode) - ;; Unless we're operating under - ;; `electric-layout-mode' (Bug#35254), the goal here - ;; will be to remove the trailing whitespace after - ;; reindentation of the previous line because that - ;; may have (re)introduced it. - (goto-char before) - ;; We were at EOL in marker `before' before the call - ;; to `indent-according-to-mode' but after we may - ;; not be (Bug#15767). - (when (and (eolp)) - (delete-horizontal-space t)))))) + (goto-char before) + ;; We were at EOL in marker `before' before the call + ;; to `indent-according-to-mode' but after we may + ;; not be (Bug#15767). + (when (and (eolp)) + (delete-horizontal-space t))))) (unless (and electric-indent-inhibit (not at-newline)) (condition-case-unless-debug () @@ -173,149 +167,6 @@ or comment." (define-globalized-minor-mode electric-indent-mode electric-indent-local-mode electric-indent-local-mode) -;;; Electric newlines after/before/around some chars. - -(defvar electric-layout-rules nil - "List of rules saying where to automatically insert newlines. - -Each rule has the form (CHAR . WHERE), the rule matching if the -character just inserted was CHAR. WHERE specifies where to -insert newlines, and can be: - -* one of the symbols `before', `after', `around', `after-stay', - or nil. - -* a list of the preceding symbols, processed in order of - appearance to insert multiple newlines; - -* a function of no arguments that returns one of the previous - values. - -Each symbol specifies where, in relation to the position POS of -the character inserted, the newline character(s) should be -inserted. `after-stay' means insert a newline after POS but stay -in the same place. - -Instead of the (CHAR . WHERE) form, a rule can also be just a -function of a single argument, the character just inserted. It -is called at that position, and should return a value compatible with -WHERE if the rule matches, or nil if it doesn't match. - -If multiple rules match, only first one is executed.") - -;; TODO: Make this a defcustom? -(defvar electric-layout-allow-duplicate-newlines nil - "If non-nil, allow duplication of `before' newlines.") - -(defun electric-layout-post-self-insert-function () - (when electric-layout-mode - (electric-layout-post-self-insert-function-1))) - -(defvar electric-pair-open-newline-between-pairs) - -;; for edebug's sake, a separate function -(defun electric-layout-post-self-insert-function-1 () - (let* ((pos (electric--after-char-pos)) - probe - (rules electric-layout-rules) - (rule - (catch 'done - (when pos - (while (setq probe (pop rules)) - (cond ((and (consp probe) - (eq (car probe) last-command-event)) - (throw 'done (cdr probe))) - ((functionp probe) - (let ((res - (save-excursion - (goto-char pos) - (funcall probe last-command-event)))) - (when res (throw 'done res)))))))))) - (when rule - (goto-char pos) - (when (functionp rule) (setq rule (funcall rule))) - (dolist (sym (if (symbolp rule) (list rule) rule)) - (let* ((nl-after - (lambda () - ;; FIXME: we use `newline', which calls - ;; `self-insert-command' and ran - ;; `post-self-insert-hook' recursively. It happened - ;; to make `electric-indent-mode' work automatically - ;; with `electric-layout-mode' (at the cost of - ;; re-indenting lines multiple times), but I'm not - ;; sure it's what we want. - ;; - ;; JT@19/02/22: Indeed in the case of `before' - ;; newlines, re-indentation is prevented. - ;; - ;; FIXME: when `newline'ing, we exceptionally - ;; prevent a specific behavior of - ;; `electric-pair-mode', that of opening an extra - ;; newline between newly inserted matching paris. - ;; In theory that behavior should be provided by - ;; `electric-layout-mode' instead, which should be - ;; possible given the current API. - ;; - ;; FIXME: check eolp before inserting \n? - (let ((electric-layout-mode nil) - (electric-pair-open-newline-between-pairs nil)) - (newline 1 t)))) - (nl-before - (lambda () - (save-excursion - (goto-char (1- pos)) - ;; Normally, we don't duplicate newlines, but when - ;; we're being called for i.e. a closer brace for - ;; `electric-pair-mode' generally make sense. So - ;; consult `electric-layout-allow-duplicate-newlines' - (unless (and (not electric-layout-allow-duplicate-newlines) - (progn (skip-chars-backward " \t") - (bolp))) - ;; FIXME: JT@19/03/22: Make sure the `before' - ;; newline being inserted here does not trigger - ;; reindentation. It doesn't seem to be our job - ;; to do so and it break with `cc-mode's - ;; indentation function. Later on we can add a - ;; before-and-maybe-indent, or if the user - ;; really wants to reindent, then - ;; `last-command-event' should be in - ;; `electric-indent-chars'. - (let ((electric-indent-inhibit 'electric-layout-mode)) - (funcall nl-after))))))) - (pcase sym - ('before (funcall nl-before)) - ('after (funcall nl-after)) - ('after-stay (save-excursion (funcall nl-after))) - ('around (funcall nl-before) (funcall nl-after)))))))) - -;;;###autoload -(define-minor-mode electric-layout-mode - "Automatically insert newlines around some chars. - -The variable `electric-layout-rules' says when and how to insert newlines." - :global t :group 'electricity - (cond (electric-layout-mode - (add-hook 'post-self-insert-hook - #'electric-layout-post-self-insert-function - 40)) - (t - (remove-hook 'post-self-insert-hook - #'electric-layout-post-self-insert-function)))) - -;;;###autoload -(define-minor-mode electric-layout-local-mode - "Toggle `electric-layout-mode' only in this buffer." - :variable ( electric-layout-mode . - (lambda (val) (setq-local electric-layout-mode val))) - (cond - ((eq electric-layout-mode (default-value 'electric-layout-mode)) - (kill-local-variable 'electric-layout-mode)) - ((not (default-value 'electric-layout-mode)) - ;; Locally enabled, but globally disabled. - (electric-layout-mode 1) ; Setup the hooks. - (setq-default electric-layout-mode nil) ; But keep it globally disabled. - ))) - ;;; Electric quoting. (defcustom electric-quote-comment t diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index d75256c2e7c..91e755aba74 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -62,7 +62,6 @@ (require 'rx)) (defvar ido-cur-list) -(defvar electric-layout-rules) (declare-function ido-mode "ido" (&optional arg)) (declare-function treesit-parser-create "treesit.c") (declare-function treesit-induce-sparse-tree "treesit.c") @@ -3794,8 +3793,6 @@ Currently there are `js-mode' and `js-ts-mode'." (setq-local comment-multi-line t) (setq-local electric-indent-chars (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds "[]*". - (setq-local electric-layout-rules - '((?\; . after) (?\{ . after) (?\} . before))) (let ((c-buffer-is-cc-mode t)) ;; FIXME: These are normally set by `c-basic-common-init'. Should @@ -3908,8 +3905,6 @@ See `treesit-thing-settings' for more information.") ;; Electric-indent. (setq-local electric-indent-chars (append "{}():;,<>/" electric-indent-chars)) ;FIXME: js2-mode adds "[]*". - (setq-local electric-layout-rules - '((?\; . after) (?\{ . after) (?\} . before))) (setq-local syntax-propertize-function #'js-ts--syntax-propertize) ;; Tree-sitter setup. diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index cc47880bcbb..26529ffdc3c 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el @@ -128,9 +128,6 @@ parenthetical grouping.") ["Auto Fill" auto-fill-mode :style toggle :selected auto-fill-function :help "Automatic line breaking"] - ["Electric Layout" electric-layout-mode - :style toggle :selected electric-layout-mode - :help "Automatically insert newlines around some chars"] "---" ("Debug" ["Send Current Line" octave-send-line t] @@ -536,8 +533,6 @@ Non-nil means always go to the next Octave code line after sending." (put-text-property (match-beginning 1) (match-end 1) 'syntax-table (string-to-syntax "\"'"))))) -(defvar electric-layout-rules) - ;; FIXME: cc-mode.el also adds an entry for .m files, mapping them to ;; objc-mode. We here rely on the fact that loaddefs.el is filled in ;; alphabetical order, so cc-mode.el comes before octave-mode.el, which lets @@ -588,9 +583,6 @@ Key bindings: (setq-local electric-indent-chars (cons ?\; electric-indent-chars)) - ;; IIUC matlab-mode takes the opposite approach: it makes RET insert - ;; a ";" at those places where it's correct (i.e. outside of parens). - (setq-local electric-layout-rules '((?\; . after))) (setq-local comment-use-syntax t) (setq-local comment-start octave-comment-start) diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el index 13d5d7f9451..a182e303880 100644 --- a/lisp/progmodes/perl-mode.el +++ b/lisp/progmodes/perl-mode.el @@ -794,7 +794,6 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'." (add-hook 'syntax-propertize-extend-region-functions #'syntax-propertize-multiline 'append 'local) ;; Electricity. - ;; FIXME: setup electric-layout-rules. (setq-local electric-indent-chars (append '(?\{ ?\} ?\; ?\:) electric-indent-chars)) (add-hook 'electric-indent-functions #'perl-electric-noindent-p nil t) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index fab8456c9d3..58126fc8c09 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1078,10 +1078,10 @@ using a command like `project-find-file'." Interactively, prompt for FILENAME, defaulting to the root directory of the current project." - (interactive - (list (read-file-name "Find file in project: " - (project-root (project-current t)) nil - (confirm-nonexistent-file-or-buffer)))) + (declare (interactive-only find-file)) + (interactive (list (read-file-name "Find project file: " + (project-root (project-current t)) nil + (confirm-nonexistent-file-or-buffer)))) (find-file filename t)) ;;;###autoload diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index b1288f17d86..1c0f3f2790e 100644 --- a/lisp/progmodes/typescript-ts-mode.el +++ b/lisp/progmodes/typescript-ts-mode.el @@ -480,8 +480,6 @@ This mode is intended to be inherited by concrete major modes." ;; Electric (setq-local electric-indent-chars (append "{}():;,<>/" electric-indent-chars)) - (setq-local electric-layout-rules - '((?\; . after) (?\{ . after) (?\} . before))) ;; Navigation. (setq-local treesit-defun-type-regexp (regexp-opt '("class_declaration" diff --git a/lisp/simple.el b/lisp/simple.el index 889702ed65b..a375e9deb1a 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -617,10 +617,6 @@ This hook is run by `delete-selection-uses-region-p', which see.") "Insert a newline, and move to left margin of the new line. With prefix argument ARG, insert that many newlines. -If `electric-indent-mode' is enabled, this indents the final new line -that it adds, and reindents the preceding line. To just insert -a newline, use \\[electric-indent-just-newline]. - If `auto-fill-mode' is enabled, this may cause automatic line breaking of the preceding line. A non-nil ARG inhibits this. diff --git a/test/lisp/calculator-tests.el b/test/lisp/calculator-tests.el deleted file mode 100644 index 5b485fe6dc5..00000000000 --- a/test/lisp/calculator-tests.el +++ /dev/null @@ -1,57 +0,0 @@ -;;; calculator-tests.el --- Test suite for calculator. -*- lexical-binding: t -*- - -;; Copyright (C) 2021-2024 Free Software Foundation, Inc. - -;; This file is part of GNU Emacs. - -;; GNU Emacs is free software: you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; GNU Emacs is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs. If not, see . - -;;; Code: -(require 'ert) -(require 'calculator) - -(ert-deftest calculator-test-calculator-string-to-number () - (dolist (x '(("" 0.0) - ("+" 0.0) - ("-" 0.0) - ("." 0.0) - ("+." 0.0) - ("-." -0.0) - (".-" 0.0) - ("--." 0.0) - ("-0.0e" -0.0) - ("1e1" 10.0) - ("1e+1" 10.0) - ("1e-1" 0.1) - ("+1e1" 10.0) - ("-1e1" -10.0) - ("+1e-1" 0.1) - ("-1e-1" -0.1) - (".1.e1" 0.1) - (".1..e1" 0.1) - ("1e+1.1" 10.0) - ("-2e-1.1" -0.2))) - (pcase x - (`(,str ,expected) - (let ((calculator-input-radix nil)) - (should (equal (calculator-string-to-number str) expected))))))) - -(ert-deftest calculator-expt () - (should (= (calculator-expt 2 -1) 0.5)) - (should (= (calculator-expt -2 2) 4)) - (should (= (calculator-expt -2 3) -8)) - (should (= (calculator-expt 2 64) 18446744073709551616))) - -(provide 'calculator-tests) -;;; calculator-tests.el ends here diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el index 720313511a6..41f0550e711 100644 --- a/test/lisp/electric-tests.el +++ b/test/lisp/electric-tests.el @@ -34,17 +34,14 @@ (defun call-with-saved-electric-modes (fn) (let ((saved-electric (if electric-pair-mode 1 -1)) - (saved-layout (if electric-layout-mode 1 -1)) (saved-indent (if electric-indent-mode 1 -1)) (blink-paren-function nil)) (electric-pair-mode -1) - (electric-layout-mode -1) (electric-indent-mode -1) (unwind-protect (funcall fn) (electric-pair-mode saved-electric) - (electric-indent-mode saved-indent) - (electric-layout-mode saved-layout)))) + (electric-indent-mode saved-indent)))) (defmacro save-electric-modes (&rest body) (declare (indent defun) (debug t)) @@ -522,34 +519,12 @@ baz\"\"" :bindings '((electric-pair-text-pairs . ((?\` . ?\'))))) -;;; `js-mode' has `electric-layout-rules' for '{ and '} -;;; (define-electric-pair-test js-mode-braces "" "{" :expected-string "{}" :expected-point 2 :modes '(js-mode) :fixture-fn (lambda () (electric-pair-mode 1))) - -(define-electric-pair-test js-mode-braces-with-layout - "" "{" :expected-string "{\n\n}" :expected-point 3 - :modes '(js-mode) - :test-in-comments nil - :test-in-strings nil - :fixture-fn (lambda () - (electric-layout-mode 1) - (electric-pair-mode 1))) - -(define-electric-pair-test js-mode-braces-with-layout-and-indent - "" "{" :expected-string "{\n \n}" :expected-point 7 - :modes '(js-mode) - :test-in-comments nil - :test-in-strings nil - :fixture-fn (lambda () - (electric-pair-mode 1) - (electric-indent-mode 1) - (electric-layout-mode 1))) - ;;; Backspacing ;;; TODO: better tests @@ -854,138 +829,5 @@ baz\"\"" :bindings '((comment-start . "