diff options
Diffstat (limited to 'lisp/emacs-lisp/lisp.el')
-rw-r--r-- | lisp/emacs-lisp/lisp.el | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 0fe18b6e94c..93d43e319a5 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -60,8 +60,8 @@ Should take the same arguments and behave similarly to `forward-sexp'.") With ARG, do it that many times. Negative arg -N means move backward across N balanced expressions. This command assumes point is not in a string or comment. Calls -`forward-sexp-function' to do the work, if that is non-nil. If -unable to move over a sexp, signal `scan-error' with three +`forward-sexp-function' to do the work, if that is non-nil. +If unable to move over a sexp, signal `scan-error' with three arguments: a message, the start of the obstacle (usually a parenthesis or list marker of some kind), and end of the obstacle." @@ -164,7 +164,7 @@ This command will also work on other parentheses-like expressions defined by the current language mode. With ARG, do this that many times. A negative argument means move backward but still to a less deep spot. If ESCAPE-STRINGS is non-nil (as it is -interactively), move out of enclosing strings as well. If +interactively), move out of enclosing strings as well. If NO-SYNTAX-CROSSING is non-nil (as it is interactively), prefer to break out of any enclosing string instead of moving to the start of a list broken across multiple strings. On error, location of @@ -339,12 +339,18 @@ is called as a function to find the defun's beginning." ((or defun-prompt-regexp open-paren-in-column-0-is-defun-start) (and (< arg 0) (not (eobp)) (forward-char 1)) - (and (re-search-backward (if defun-prompt-regexp - (concat (if open-paren-in-column-0-is-defun-start - "^\\s(\\|" "") - "\\(?:" defun-prompt-regexp "\\)\\s(") - "^\\s(") - nil 'move arg) + (and (let (found) + (while + (and (setq found + (re-search-backward + (if defun-prompt-regexp + (concat (if open-paren-in-column-0-is-defun-start + "^\\s(\\|" "") + "\\(?:" defun-prompt-regexp "\\)\\s(") + "^\\s(") + nil 'move arg)) + (nth 8 (syntax-ppss)))) + found) (progn (goto-char (1- (match-end 0))) t))) @@ -364,8 +370,9 @@ is called as a function to find the defun's beginning." (arg-+ve (> arg 0))) (save-restriction (widen) - (let ((ppss (let (syntax-begin-function) - (syntax-ppss))) + (let ((ppss (with-suppressed-warnings ((obsolete syntax-begin-function)) + (let (syntax-begin-function) + (syntax-ppss)))) ;; position of least enclosing paren, or nil. encl-pos) ;; Back out of any comment/string, so that encl-pos will always @@ -639,7 +646,7 @@ Interactively, the behavior depends on `narrow-to-defun-include-comments'." (re-search-backward "^\n" (- (point) 1) t) (narrow-to-region beg end)))) -(defvar insert-pair-alist +(defcustom insert-pair-alist '((?\( ?\)) (?\[ ?\]) (?\{ ?\}) (?\< ?\>) (?\" ?\") (?\' ?\') (?\` ?\')) "Alist of paired characters inserted by `insert-pair'. Each element looks like (OPEN-CHAR CLOSE-CHAR) or (COMMAND-CHAR @@ -649,7 +656,16 @@ or without modifiers, are inserted by `insert-pair'. If COMMAND-CHAR is specified, it is a character that triggers the insertion of the open/close pair, and COMMAND-CHAR itself isn't -inserted.") +inserted." + :type '(repeat (choice (list :tag "Pair" + (character :tag "Open") + (character :tag "Close")) + (list :tag "Triple" + (character :tag "Command") + (character :tag "Open") + (character :tag "Close")))) + :group 'lisp + :version "27.1") (defun insert-pair (&optional arg open close) "Enclose following ARG sexps in a pair of OPEN and CLOSE characters. @@ -717,11 +733,13 @@ This command assumes point is not in a string or comment." (interactive "P") (insert-pair arg ?\( ?\))) -(defun delete-pair () - "Delete a pair of characters enclosing the sexp that follows point." - (interactive) - (save-excursion (forward-sexp 1) (delete-char -1)) - (delete-char 1)) +(defun delete-pair (&optional arg) + "Delete a pair of characters enclosing ARG sexps following point. +A negative ARG deletes a pair of characters around preceding ARG sexps." + (interactive "p") + (unless arg (setq arg 1)) + (save-excursion (forward-sexp arg) (delete-char (if (> arg 0) -1 1))) + (delete-char (if (> arg 0) 1 -1))) (defun raise-sexp (&optional arg) "Raise ARG sexps higher up the tree." |