[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Insert character pairs

From: Juri Linkov
Subject: Re: Insert character pairs
Date: Sun, 02 May 2004 19:19:44 +0300
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

> Maybe, a better name is `move-up-list' (however, not good since
> the word `move' often means `move the point') or `lift-up-list'?
> The command `promote-list' is basically opposite to `insert-parentheses',
> so another possible name is `remove-parentheses', but it is misleading,
> because it removes more than only enclosing parentheses.

I propose to bind `rise-up-list' to currently unused `C-x C-M-u'.
The reason is that it is similar to `backward-up-list' (`C-M-u'),
but with the prefix C-x will move the list backward out of one level
of parentheses instead of moving the point as `backward-up-list' does.

And while on this topic, another suggestion is to add a prefix
argument to the command C-M-q (`indent-sexp') which currently
has no prefix argument.  This can be similar to M-q (`fill-paragraph')
whose prefix argument adds a special meaning to justify paragraphs.
C-M-q without prefix will work exactly as it currently works,
but with a prefix will pretty-print the list after point.
This is relevant only for emacs-lisp-mode and buffers
in lisp-interaction-mode like the *scratch* buffer.

Index: lisp/emacs-lisp/lisp-mode.el
RCS file: /cvsroot/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.155
diff -U4 -r1.155 lisp-mode.el
--- lisp/emacs-lisp/lisp-mode.el        22 Mar 2004 15:31:46 -0000      1.155
+++ lisp/emacs-lisp/lisp-mode.el        2 May 2004 15:13:58 -0000
@@ -238,8 +238,9 @@
     (setq emacs-lisp-mode-map (make-sparse-keymap))
     (set-keymap-parent emacs-lisp-mode-map lisp-mode-shared-map)
     (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol)
     (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
+    (define-key emacs-lisp-mode-map "\e\C-q" 'indent-or-pp-sexp)
     (define-key emacs-lisp-mode-map [menu-bar] (make-sparse-keymap))
     (define-key emacs-lisp-mode-map [menu-bar emacs-lisp]
       (cons "Emacs-Lisp" map))
     (define-key map [edebug-defun]
@@ -368,8 +369,9 @@
 (defvar lisp-interaction-mode-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map lisp-mode-shared-map)
     (define-key map "\e\C-x" 'eval-defun)
+    (define-key map "\e\C-q" 'indent-or-pp-sexp)
     (define-key map "\e\t" 'lisp-complete-symbol)
     (define-key map "\n" 'eval-print-last-sexp)
   "Keymap for Lisp Interaction mode.
@@ -1082,8 +1084,19 @@
       (and (bolp) (not (eolp))
       (indent-sexp endmark)
       (set-marker endmark nil))))
+(defun indent-or-pp-sexp (&optional arg)
+  "Indent each line of the list or, with argument, pretty-printify the list."
+  (interactive "P")
+  (if arg
+      (let* (p (str (pp-to-string (save-excursion
+                                    (prog1 (read (current-buffer))
+                                      (setq p (point)))))))
+        (delete-region (point) p)
+        (save-excursion (insert str)))
+    (indent-sexp)))
 ;;;; Lisp paragraph filling commands.
 (defcustom emacs-lisp-docstring-fill-column 65

Juri Linkov

reply via email to

[Prev in Thread] Current Thread [Next in Thread]