diff options
Diffstat (limited to 'lisp/simple.el')
-rw-r--r-- | lisp/simple.el | 102 |
1 files changed, 78 insertions, 24 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index e54cbed7a76..26710e6d53d 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -549,7 +549,7 @@ It must be called via `run-hook-with-args-until-success' with no arguments. If any function on this hook returns a non-nil value, `delete-selection-mode' will act on that value (see `delete-selection-helper') and will usually delete the region. If all the functions on this hook return -nil, it is an indiction that `self-insert-command' needs the region +nil, it is an indication that `self-insert-command' needs the region untouched by `delete-selection-mode' and will itself do whatever is appropriate with the region. Any function on `post-self-insert-hook' that acts on the region should @@ -1278,7 +1278,19 @@ that uses or sets the mark." ;; Counting lines, one way or another. -(defvar-local goto-line-history nil +(defcustom goto-line-history-local nil + "If this option is nil, `goto-line-history' is shared between all buffers. +If it is non-nil, each buffer has its own value of this history list. + +Note that on changing from non-nil to nil, the former contents of +`goto-line-history' for each buffer are discarded on use of +`goto-line' in that buffer." + :group 'editing + :type 'boolean + :safe #'booleanp + :version "28.1") + +(defvar goto-line-history nil "History of values entered with `goto-line'.") (defun goto-line-read-args (&optional relative) @@ -1296,6 +1308,11 @@ that uses or sets the mark." (if buffer (concat " in " (buffer-name buffer)) ""))) + ;; Has the buffer locality of `goto-line-history' changed? + (cond ((and goto-line-history-local (not (local-variable-p 'goto-line-history))) + (make-local-variable 'goto-line-history)) + ((and (not goto-line-history-local) (local-variable-p 'goto-line-history)) + (kill-local-variable 'goto-line-history))) ;; Read the argument, offering that number (if any) as default. (list (read-number (format "Goto%s line%s: " (if (buffer-narrowed-p) @@ -1907,13 +1924,13 @@ to get different commands to edit and resubmit." (defcustom read-extended-command-predicate nil "Predicate to use to determine which commands to include when completing. If it's nil, include all the commands. -If it's a functoion, it will be called with two parameters: the +If it's a function, it will be called with two parameters: the symbol of the command and a buffer. The predicate should return non-nil if the command should be present when doing `M-x TAB' in that buffer." :version "28.1" :group 'completion - :type `(choice (const :tag "Don't exclude any commands" nil) + :type '(choice (const :tag "Don't exclude any commands" nil) (const :tag "Exclude commands irrelevant to current buffer's mode" command-completion-default-include-p) (function :tag "Other function"))) @@ -1977,6 +1994,26 @@ This function uses the `read-extended-command-predicate' user option." (funcall read-extended-command-predicate sym buffer))))) t nil 'extended-command-history)))) +(defun command-completion-using-modes-p (symbol buffer) + "Say whether SYMBOL has been marked as a mode-specific command in BUFFER." + ;; Check the modes. + (let ((modes (command-modes symbol))) + ;; Common case: Just a single mode. + (if (null (cdr modes)) + (or (provided-mode-derived-p + (buffer-local-value 'major-mode buffer) (car modes)) + (memq (car modes) + (buffer-local-value 'local-minor-modes buffer)) + (memq (car modes) global-minor-modes)) + ;; Uncommon case: Multiple modes. + (apply #'provided-mode-derived-p + (buffer-local-value 'major-mode buffer) + modes) + (seq-intersection modes + (buffer-local-value 'local-minor-modes buffer) + #'eq) + (seq-intersection modes global-minor-modes #'eq)))) + (defun command-completion-default-include-p (symbol buffer) "Say whether SYMBOL should be offered as a completion. If there's a `completion-predicate' for SYMBOL, the result from @@ -1987,24 +2024,8 @@ BUFFER." (if (get symbol 'completion-predicate) ;; An explicit completion predicate takes precedence. (funcall (get symbol 'completion-predicate) symbol buffer) - ;; Check the modes. - (let ((modes (command-modes symbol))) - (or (null modes) - ;; Common case: Just a single mode. - (if (null (cdr modes)) - (or (provided-mode-derived-p - (buffer-local-value 'major-mode buffer) (car modes)) - (memq (car modes) - (buffer-local-value 'local-minor-modes buffer)) - (memq (car modes) global-minor-modes)) - ;; Uncommon case: Multiple modes. - (apply #'provided-mode-derived-p - (buffer-local-value 'major-mode buffer) - modes) - (seq-intersection modes - (buffer-local-value 'local-minor-modes buffer) - #'eq) - (seq-intersection modes global-minor-modes #'eq)))))) + (or (null (command-modes symbol)) + (command-completion-using-modes-p symbol buffer)))) (defun command-completion-with-modes-p (modes buffer) "Say whether MODES are in action in BUFFER. @@ -2172,6 +2193,38 @@ invoking, give a prefix argument to `execute-extended-command'." suggest-key-bindings 2)))))))) +(defun execute-extended-command-for-buffer (prefixarg &optional + command-name typed) + "Query user for a command relevant for the current mode, and then execute it. +This is like `execute-extended-command', but it limits the +completions to commands that are particularly relevant to the +current buffer. This includes commands that have been marked as +being specially designed for the current major mode (and enabled +minor modes), as well as commands bound in the active local key +maps." + (declare (interactive-only command-execute)) + (interactive + (let* ((execute-extended-command--last-typed nil) + (keymaps + ;; The major mode's keymap and any active minor modes. + (cons + (current-local-map) + (mapcar + #'cdr + (seq-filter + (lambda (elem) + (symbol-value (car elem))) + minor-mode-map-alist)))) + (read-extended-command-predicate + (lambda (symbol buffer) + (or (command-completion-using-modes-p symbol buffer) + (where-is-internal symbol keymaps))))) + (list current-prefix-arg + (read-extended-command) + execute-extended-command--last-typed))) + (with-suppressed-warnings ((interactive-only execute-extended-command)) + (execute-extended-command prefixarg command-name typed))) + (defun command-execute (cmd &optional record-flag keys special) ;; BEWARE: Called directly from the C code. "Execute CMD as an editor command. @@ -5959,8 +6012,9 @@ START and END specify the portion of the current buffer to be copied." (defvar activate-mark-hook nil "Hook run when the mark becomes active. -It is also run at the end of a command, if the mark is active and -it is possible that the region may have changed.") +It is also run when the region is reactivated, for instance after +using a command that switches back to a buffer that has an active +mark.") (defvar deactivate-mark-hook nil "Hook run when the mark becomes inactive.") |