emacs-devel
[Top][All Lists]
Advanced

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

Re: TAB when the region is active


From: Juri Linkov
Subject: Re: TAB when the region is active
Date: Mon, 24 Sep 2007 03:07:57 +0300
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.50 (gnu/linux)

> I have committed the patch.
>
> cc-mode would need to be updated to do the same thing. I emailed the
> maintainer.
>
> Other major modes might need updates too. We can do them as soon as we
> find out they need changes.

Thanks!  It's a pity this very good feature doesn't work yet in c-mode.
I also tried it in some other modes (fundamental-mode, text-mode)
and it doesn't do something useful here.  It inserts a single TAB whereas
C-M-\ (`indent-region') tries to indent the region.  However, what C-M-\
does in text modes is not useful too because it shifts each consequent
line relative to the previous line in a staircase-like style.
So perhaps there is nothing useful it can do in text modes.

What would be useful to do in text modes is to make a similar change for
M-q (`fill-paragraph').  When the region is active in transient-mark-mode,
then M-q would call `fill-region' instead of `fill-paragraph'.

Please note that there was a keybinding for `fill-region' in bindings.el
but currently it is commented out because there are no free keybindings
for it.  Using M-q to fill the active region would be convenient for users
of transient-mark-mode.

Below is a patch that implement the new command `fill-paragraph-or-region':

Index: lisp/bindings.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/bindings.el,v
retrieving revision 1.184
diff -c -r1.184 bindings.el
*** lisp/bindings.el    20 Sep 2007 21:49:18 -0000      1.184
--- lisp/bindings.el    24 Sep 2007 00:04:22 -0000
***************
*** 1041,1048 ****
  (define-key ctl-x-map "rw" 'window-configuration-to-register)
  (define-key ctl-x-map "rf" 'frame-configuration-to-register)
  
! (define-key esc-map "q" 'fill-paragraph)
! ;; (define-key esc-map "g" 'fill-region)
  (define-key ctl-x-map "." 'set-fill-prefix)
  
  (define-key esc-map "{" 'backward-paragraph)
--- 1041,1047 ----
  (define-key ctl-x-map "rw" 'window-configuration-to-register)
  (define-key ctl-x-map "rf" 'frame-configuration-to-register)
  
! (define-key esc-map "q" 'fill-paragraph-or-region)
  (define-key ctl-x-map "." 'set-fill-prefix)
  
  (define-key esc-map "{" 'backward-paragraph)

Index: lisp/textmodes/fill.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/textmodes/fill.el,v
retrieving revision 1.205
diff -c -r1.205 fill.el
*** lisp/textmodes/fill.el      26 Jul 2007 05:27:32 -0000      1.205
--- lisp/textmodes/fill.el      24 Sep 2007 00:04:56 -0000
***************
*** 1007,1012 ****
--- 1007,1022 ----
          (goto-char end))))
      fill-pfx))
  
+ (defun fill-paragraph-or-region (arg)
+   "Fill the active region or paragraph."
+   (interactive (progn
+                (barf-if-buffer-read-only)
+                (list (if current-prefix-arg 'full))))
+   (if (and transient-mark-mode mark-active
+          (not (eq (region-beginning) (region-end))))
+       (fill-region (region-beginning) (region-end) arg)
+     (fill-paragraph arg)))
+ 
  
  (defcustom default-justification 'left
    "*Method of justifying text not otherwise specified.

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

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