From 5891bf24d99843c76f56ec6f540b98d83d942426 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sat, 1 May 2004 03:58:43 +0000 Subject: [PATCH] (beginning-of-defun, end-of-defun): Push mark on the first call of successive command calls. (insert-pair): New fun created from `insert-parentheses' with `open' and `close' arguments added. Enclose active regions in paired characters. Compare adjacent characters syntax with inserted characters syntax before inserting a space. (insert-parentheses): Call `insert-pair' with ?\( ?\). --- lisp/emacs-lisp/lisp.el | 57 +++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index e1ed508b865..8fe839b474d 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -175,6 +175,8 @@ open-parenthesis, and point ends up at the beginning of the line. If variable `beginning-of-defun-function' is non-nil, its value is called as a function to find the defun's beginning." (interactive "p") + (and (eq this-command 'beginning-of-defun) + (or (eq last-command 'beginning-of-defun) (push-mark))) (and (beginning-of-defun-raw arg) (progn (beginning-of-line) t))) @@ -223,6 +225,8 @@ matches the open-parenthesis that starts a defun; see function If variable `end-of-defun-function' is non-nil, its value is called as a function to find the defun's end." (interactive "p") + (and (eq this-command 'end-of-defun) + (or (eq last-command 'end-of-defun) (push-mark))) (if (or (null arg) (= arg 0)) (setq arg 1)) (if end-of-defun-function (if (> arg 0) @@ -302,29 +306,48 @@ Optional ARG is ignored." (end-of-defun) (narrow-to-region beg (point))))) -(defun insert-parentheses (arg) - "Enclose following ARG sexps in parentheses. Leave point after open-paren. +(defun insert-pair (arg &optional open close) + "Enclose following ARG sexps in a pair of OPEN and CLOSE characters. +Leave point after the first character. A negative ARG encloses the preceding ARG sexps instead. -No argument is equivalent to zero: just insert `()' and leave point between. +No argument is equivalent to zero: just insert characters +and leave point between. If `parens-require-spaces' is non-nil, this command also inserts a space -before and after, depending on the surrounding characters." +before and after, depending on the surrounding characters. +If region is active, insert enclosing characters at region boundaries." (interactive "P") (if arg (setq arg (prefix-numeric-value arg)) (setq arg 0)) - (cond ((> arg 0) (skip-chars-forward " \t")) - ((< arg 0) (forward-sexp arg) (setq arg (- arg)))) - (and parens-require-spaces - (not (bobp)) - (memq (char-syntax (preceding-char)) '(?w ?_ ?\) )) - (insert " ")) - (insert ?\() - (save-excursion - (or (eq arg 0) (forward-sexp arg)) - (insert ?\)) + (or open (setq open ?\()) + (or close (setq close ?\))) + (if (and transient-mark-mode mark-active) + (progn + (save-excursion (goto-char (region-end)) (insert close)) + (save-excursion (goto-char (region-beginning)) (insert open))) + (cond ((> arg 0) (skip-chars-forward " \t")) + ((< arg 0) (forward-sexp arg) (setq arg (- arg)))) (and parens-require-spaces - (not (eobp)) - (memq (char-syntax (following-char)) '(?w ?_ ?\( )) - (insert " ")))) + (not (bobp)) + (memq (char-syntax (preceding-char)) (list ?w ?_ (char-syntax close))) + (insert " ")) + (insert open) + (save-excursion + (or (eq arg 0) (forward-sexp arg)) + (insert close) + (and parens-require-spaces + (not (eobp)) + (memq (char-syntax (following-char)) (list ?w ?_ (char-syntax open))) + (insert " "))))) + +(defun insert-parentheses (arg) + "Enclose following ARG sexps in parentheses. Leave point after open-paren. +A negative ARG encloses the preceding ARG sexps instead. +No argument is equivalent to zero: just insert `()' and leave point between. +If `parens-require-spaces' is non-nil, this command also inserts a space +before and after, depending on the surrounding characters. +If region is active, insert enclosing characters at region boundaries." + (interactive "P") + (insert-pair arg ?\( ?\))) (defun move-past-close-and-reindent () "Move past next `)', delete indentation before it, then indent after it." -- 2.39.5