* TAB when the region is active
@ 2007-09-14 21:59 Dan Nicolaescu
2007-09-16 5:35 ` Richard Stallman
2007-09-16 18:48 ` Lennart Borgman
0 siblings, 2 replies; 30+ messages in thread
From: Dan Nicolaescu @ 2007-09-14 21:59 UTC (permalink / raw)
To: emacs-devel
A few commands (like replace-string/regexp, undo, etc) change their
behavior if transient-mark-mode is on and the mark is active: they
apply only to the active region.
Similarly, wouldn't it be better if TAB would run indent-region if the
region is active?
Opinions?
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-14 21:59 TAB when the region is active Dan Nicolaescu
@ 2007-09-16 5:35 ` Richard Stallman
2007-09-17 4:09 ` Dan Nicolaescu
2007-09-16 18:48 ` Lennart Borgman
1 sibling, 1 reply; 30+ messages in thread
From: Richard Stallman @ 2007-09-16 5:35 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: emacs-devel
Similarly, wouldn't it be better if TAB would run indent-region if the
region is active?
The idea is logical, but we need to ask users if they find the change
annoying.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-14 21:59 TAB when the region is active Dan Nicolaescu
2007-09-16 5:35 ` Richard Stallman
@ 2007-09-16 18:48 ` Lennart Borgman
2007-09-16 19:17 ` Paul Pogonyshev
` (2 more replies)
1 sibling, 3 replies; 30+ messages in thread
From: Lennart Borgman @ 2007-09-16 18:48 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 453 bytes --]
On 9/14/07, Dan Nicolaescu <dann@ics.uci.edu> wrote:
>
>
> A few commands (like replace-string/regexp, undo, etc) change their
> behavior if transient-mark-mode is on and the mark is active: they
> apply only to the active region.
>
> Similarly, wouldn't it be better if TAB would run indent-region if the
> region is active?
>
> Opinions?
I agree, this is a natural extension and very useful. (And this is the way
it works in nxhtml-mode currently.)
[-- Attachment #1.2: Type: text/html, Size: 743 bytes --]
[-- Attachment #2: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-16 18:48 ` Lennart Borgman
@ 2007-09-16 19:17 ` Paul Pogonyshev
2007-09-16 20:32 ` Drew Adams
2007-09-17 3:59 ` Richard Stallman
2 siblings, 0 replies; 30+ messages in thread
From: Paul Pogonyshev @ 2007-09-16 19:17 UTC (permalink / raw)
To: emacs-devel; +Cc: Dan Nicolaescu, Lennart Borgman
Lennart Borgman wrote:
> On 9/14/07, Dan Nicolaescu <dann@ics.uci.edu> wrote:
> >
> >
> > A few commands (like replace-string/regexp, undo, etc) change their
> > behavior if transient-mark-mode is on and the mark is active: they
> > apply only to the active region.
> >
> > Similarly, wouldn't it be better if TAB would run indent-region if the
> > region is active?
> >
> > Opinions?
>
> I agree, this is a natural extension and very useful. (And this is the way
> it works in nxhtml-mode currently.)
Second this.
Paul
^ permalink raw reply [flat|nested] 30+ messages in thread
* RE: TAB when the region is active
2007-09-16 18:48 ` Lennart Borgman
2007-09-16 19:17 ` Paul Pogonyshev
@ 2007-09-16 20:32 ` Drew Adams
2007-09-17 3:59 ` Richard Stallman
2 siblings, 0 replies; 30+ messages in thread
From: Drew Adams @ 2007-09-16 20:32 UTC (permalink / raw)
To: emacs-devel
> A few commands (like replace-string/regexp, undo, etc) change their
> behavior if transient-mark-mode is on and the mark is active: they
> apply only to the active region.
> Similarly, wouldn't it be better if TAB would run indent-region if the
> region is active?
OK, provided that the region is both active and nonempty. Especially since
it is not always obvious when the region is empty, doing this to an empty
region could surprise users.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-16 18:48 ` Lennart Borgman
2007-09-16 19:17 ` Paul Pogonyshev
2007-09-16 20:32 ` Drew Adams
@ 2007-09-17 3:59 ` Richard Stallman
2 siblings, 0 replies; 30+ messages in thread
From: Richard Stallman @ 2007-09-17 3:59 UTC (permalink / raw)
To: Lennart Borgman; +Cc: dann, emacs-devel
I agree, this is a natural extension and very useful. (And this is the way
it works in nxhtml-mode currently.)
This is not something that major modes ought to change. If we adopt
this for Emacs generally, as _perhaps_ we should, then that mode
should do it too. Otherwise, when we install it, we should change
nxhtml-mode to turn that off (by default, at least).
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-16 5:35 ` Richard Stallman
@ 2007-09-17 4:09 ` Dan Nicolaescu
2007-09-17 22:24 ` Richard Stallman
0 siblings, 1 reply; 30+ messages in thread
From: Dan Nicolaescu @ 2007-09-17 4:09 UTC (permalink / raw)
To: rms; +Cc: emacs-devel
Richard Stallman <rms@gnu.org> writes:
> Similarly, wouldn't it be better if TAB would run indent-region if the
> region is active?
>
> The idea is logical, but we need to ask users if they find the change
> annoying.
Given that we are not close to a release, this would be a good time to
experiment. Can you please OK such a change?
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-17 4:09 ` Dan Nicolaescu
@ 2007-09-17 22:24 ` Richard Stallman
2007-09-17 22:40 ` Lennart Borgman (gmail)
2007-09-17 23:13 ` Dan Nicolaescu
0 siblings, 2 replies; 30+ messages in thread
From: Richard Stallman @ 2007-09-17 22:24 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: emacs-devel
> The idea is logical, but we need to ask users if they find the change
> annoying.
Given that we are not close to a release, this would be a good time to
experiment. Can you please OK such a change?
I will ok trying it, if you agree to follow up in a few weeks
by reminding people to try it and say if they don't like it.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-17 22:24 ` Richard Stallman
@ 2007-09-17 22:40 ` Lennart Borgman (gmail)
2007-09-17 22:47 ` Drew Adams
2007-09-17 23:28 ` Dan Nicolaescu
2007-09-17 23:13 ` Dan Nicolaescu
1 sibling, 2 replies; 30+ messages in thread
From: Lennart Borgman (gmail) @ 2007-09-17 22:40 UTC (permalink / raw)
To: rms; +Cc: Dan Nicolaescu, Drew Adams, emacs-devel
Richard Stallman wrote:
> > The idea is logical, but we need to ask users if they find the change
> > annoying.
>
> Given that we are not close to a release, this would be a good time to
> experiment. Can you please OK such a change?
>
> I will ok trying it, if you agree to follow up in a few weeks
> by reminding people to try it and say if they don't like it.
The code below is what I currently use. There are some problems I know
about:
- I do not remember what Drew wanted to add (in another message).
- indent-according-to-mode is not supported everywhere.
BTW, there is another problem with the indentation functions. I believe
it would be useful (at least in mumamo.el) if the function that indents
a line where split into one that gives the indentation amount and one
that does the indentation (for every major mode).
(defun indent-line-or-region ()
"Indent line or region.
Only do this if indentation seems bound to \\t.
Call `indent-region' if region is active, otherwise
`indent-according-to-mode'."
(interactive)
;; Do a wild guess if we should indent or not ...
(let* ((indent-region-mode)
(t-bound (key-binding [?\t])))
(if (not
(save-match-data
(string-match "indent" (symbol-name t-bound))))
(call-interactively t-bound t)
(if (and mark-active ;; there is a visible region selected
transient-mark-mode)
(indent-region (region-beginning) (region-end))
(indent-according-to-mode))))) ;; indent line
^ permalink raw reply [flat|nested] 30+ messages in thread
* RE: TAB when the region is active
2007-09-17 22:40 ` Lennart Borgman (gmail)
@ 2007-09-17 22:47 ` Drew Adams
2007-09-17 23:28 ` Dan Nicolaescu
1 sibling, 0 replies; 30+ messages in thread
From: Drew Adams @ 2007-09-17 22:47 UTC (permalink / raw)
To: Lennart Borgman (gmail), rms; +Cc: Dan Nicolaescu, emacs-devel
> - I do not remember what Drew wanted to add (in another message).
Make sure the active region is not empty.
This should be done for pretty much all operations that do something
different when the region is active - you don't want to act specially on
just an empty region.
That's all.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-17 22:24 ` Richard Stallman
2007-09-17 22:40 ` Lennart Borgman (gmail)
@ 2007-09-17 23:13 ` Dan Nicolaescu
1 sibling, 0 replies; 30+ messages in thread
From: Dan Nicolaescu @ 2007-09-17 23:13 UTC (permalink / raw)
To: rms; +Cc: emacs-devel
Richard Stallman <rms@gnu.org> writes:
> > The idea is logical, but we need to ask users if they find the change
> > annoying.
>
> Given that we are not close to a release, this would be a good time to
> experiment. Can you please OK such a change?
>
> I will ok trying it, if you agree to follow up in a few weeks
> by reminding people to try it and say if they don't like it.
OK.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-17 22:40 ` Lennart Borgman (gmail)
2007-09-17 22:47 ` Drew Adams
@ 2007-09-17 23:28 ` Dan Nicolaescu
2007-09-19 3:42 ` Dan Nicolaescu
1 sibling, 1 reply; 30+ messages in thread
From: Dan Nicolaescu @ 2007-09-17 23:28 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: rms, Drew Adams, emacs-devel
"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> Richard Stallman wrote:
> > > The idea is logical, but we need to ask users if they find the change
> > > annoying.
> >
> > Given that we are not close to a release, this would be a good time to
> > experiment. Can you please OK such a change?
> >
> > I will ok trying it, if you agree to follow up in a few weeks
> > by reminding people to try it and say if they don't like it.
>
>
> The code below is what I currently use. There are some problems I know
> about:
Thanks. I don't know much about the code in indent.el, and I don't see
how your code would fit in the existing framework there. I would
guess that indent-for-tab-command and the functions that it calls
would need changes.
Any help with getting this right would be greatly appreciated.
> - I do not remember what Drew wanted to add (in another message).
>
> - indent-according-to-mode is not supported everywhere.
>
> BTW, there is another problem with the indentation functions. I
> believe it would be useful (at least in mumamo.el) if the function
> that indents a line where split into one that gives the indentation
> amount and one that does the indentation (for every major mode).
>
>
> (defun indent-line-or-region ()
> "Indent line or region.
> Only do this if indentation seems bound to \\t.
>
> Call `indent-region' if region is active, otherwise
> `indent-according-to-mode'."
> (interactive)
> ;; Do a wild guess if we should indent or not ...
> (let* ((indent-region-mode)
> (t-bound (key-binding [?\t])))
> (if (not
> (save-match-data
> (string-match "indent" (symbol-name t-bound))))
> (call-interactively t-bound t)
> (if (and mark-active ;; there is a visible region selected
> transient-mark-mode)
> (indent-region (region-beginning) (region-end))
> (indent-according-to-mode))))) ;; indent line
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-17 23:28 ` Dan Nicolaescu
@ 2007-09-19 3:42 ` Dan Nicolaescu
2007-09-19 5:11 ` Drew Adams
2007-09-19 13:45 ` Stefan Monnier
0 siblings, 2 replies; 30+ messages in thread
From: Dan Nicolaescu @ 2007-09-19 3:42 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: rms, Drew Adams, emacs-devel
Dan Nicolaescu <dann@ics.uci.edu> writes:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>
> > Richard Stallman wrote:
> > > > The idea is logical, but we need to ask users if they find the change
> > > > annoying.
> > >
> > > Given that we are not close to a release, this would be a good time to
> > > experiment. Can you please OK such a change?
> > >
> > > I will ok trying it, if you agree to follow up in a few weeks
> > > by reminding people to try it and say if they don't like it.
> >
> >
> > The code below is what I currently use. There are some problems I know
> > about:
Here's my first try at doing this. lisp-mode needed changes because it
binds TAB differently...
Can you please give it a spin?
Does anything need to be done for the case where TAB is used to insert
a tab character? (I don't know when that is supposed to happen and
what is the expected behavior...)
*** indent.el 26 Jul 2007 10:17:33 -0700 1.68
--- indent.el 18 Sep 2007 08:38:25 -0700
***************
*** 75,81 ****
(indent-line-to column)
(save-excursion (indent-line-to column))))
;; The normal case.
! (funcall indent-line-function)))
(defun indent-for-tab-command (&optional arg)
"Indent line in proper way for current major mode or insert a tab.
--- 75,84 ----
(indent-line-to column)
(save-excursion (indent-line-to column))))
;; The normal case.
! (if (and transient-mark-mode mark-active
! (not (eq (region-beginning) (region-end))))
! (indent-region (region-beginning) (region-end))
! (funcall indent-line-function))))
(defun indent-for-tab-command (&optional arg)
"Indent line in proper way for current major mode or insert a tab.
*** emacs-lisp/lisp-mode.el 20 Aug 2007 15:47:53 -0700 1.207
--- emacs-lisp/lisp-mode.el 18 Sep 2007 08:46:08 -0700
***************
*** 261,267 ****
(defvar lisp-mode-shared-map
(let ((map (make-sparse-keymap)))
! (define-key map "\t" 'lisp-indent-line)
(define-key map "\e\C-q" 'indent-sexp)
(define-key map "\177" 'backward-delete-char-untabify)
;; This gets in the way when viewing a Lisp file in view-mode. As
--- 261,267 ----
(defvar lisp-mode-shared-map
(let ((map (make-sparse-keymap)))
! (define-key map "\t" 'lisp-indent-line-or-region)
(define-key map "\e\C-q" 'indent-sexp)
(define-key map "\177" 'backward-delete-char-untabify)
;; This gets in the way when viewing a Lisp file in view-mode. As
***************
*** 828,833 ****
--- 828,841 ----
(> end beg))
(indent-code-rigidly beg end shift-amt)))))
+ (defun lisp-indent-line-or-region (&optional whole-exp)
+ "Indent the current line or the region if it is active."
+ (interactive "P")
+ (if (and transient-mark-mode mark-active
+ (not (eq (region-beginning) (region-end))))
+ (lisp-indent-region (region-beginning) (region-end))
+ (lisp-indent-line whole-exp)))
+
(defvar calculate-lisp-indent-last-sexp)
(defun calculate-lisp-indent (&optional parse-start)
^ permalink raw reply [flat|nested] 30+ messages in thread
* RE: TAB when the region is active
2007-09-19 3:42 ` Dan Nicolaescu
@ 2007-09-19 5:11 ` Drew Adams
2007-09-19 13:45 ` Stefan Monnier
2007-09-19 13:45 ` Stefan Monnier
1 sibling, 1 reply; 30+ messages in thread
From: Drew Adams @ 2007-09-19 5:11 UTC (permalink / raw)
To: emacs-devel
1. `indent-region' only indents lines that start within the region. There's
probably a good reason for that, but I'm not sure that's the behavior we
want here. I wonder if it wouldn't be better here to apply `indent-line'
(e.g. `lisp-indent-line') to each line, in turn, that has at least one
character (not necessarily its first character) in the region.
A typical use case for me is wanting to see what really changes when I do
`C-M-q' on a large defun (> one screen). I want, for instance, to see if
only some comment positions change or if some sexps move because I might
have an extra or a missing paren. I'll hit TAB for each of several
successive lines to see if/how they move. (You might have an alternative
that you prefer, but I often do this.)
If TAB, as proposed, will now affect the region, then I'll just select some
lines and hit TAB - great.
But, IIUC, the first line selected would need to have its beginning selected
also, or else `indent-region' won't apply to it. It would be handier, I
think, to have `lisp-indent-line' applied to each selected line, in turn.
That way, the region would show all of the lines that would be affected by
the operation. You could quickly zap the mouse over some lines to select
them, without regard to the exact beginning or end of the region, and TAB
would indent them all appropriately (in turn).
(No, I didn't try the patch; I just scanned it.)
2. BTW, does `lisp-indent-region' really do the right thing? E.g., if you
select all lines after the first one here, and then do (lisp-indent-region
(region-beginning) (region-end)), the last three lines are not indented
correctly. Is that THT?
(cond (foobar
(fibrillate) ; select this and subsequent lines
(frobnicate)
(message "Fabulous!"))
(t
(barn-owl)
(bobolink)
(message "Bar none.")))
`lisp-indent-region' gives this (is it a bug or intended?):
(cond (foobar
(fibrillate)
(frobnicate)
(message "Fabulous!"))
(t
(barn-owl) ; incorrectly indented
(bobolink)
(message "Bar none.")))
The problem I was referring to in #1 is the difference between this and what
happens if you don't start the selection at the beginning of the second
line, but in some other part of the second line (e.g. at its opening paren).
The result is then this:
(cond (foobar
(fibrillate) ; incorrect indentation (not moved)
(frobnicate) ; correctly indented relative to previous
(message "Fabulous!"))
(t
(barn-owl)
(bobolink)
(message "Bar none."))))
(Yes, you can, remembering this gotcha, always start selecting one line
ahead of what you want to indent, but I think it's clearer if the region
clearly indicates the lines to be affected.)
3. Wrt my use case mentioned in #1, yes, it might be nice to have a visual
indication of the first significant (i.e. non-comment) change in
indentation, starting at point, when you do `C-M-q'. Or perhaps even an
indication of all indentation changes. That might be done by highlighting
any added whitespace and indicating any removed whitespace in some other
way - perhaps by highlighting (differently) the chars that were moved
leftward to replace previous whitespace.
E.g., moving from the first sexp above to the second would show something
like this, where `x' indicates removed whitespace (but highlighting would be
used, not `x').
(cond (foobar
xxibrillate)
xxxxxxicate)
xxxxsage "Fabulous!"))
xxx
xxxxxxxxl)
xxxxxxink)
(message "Bar none.")))
Apologies for adding topics. Only #1 is relevant to this thread. (And
perhaps #2.)
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-19 3:42 ` Dan Nicolaescu
2007-09-19 5:11 ` Drew Adams
@ 2007-09-19 13:45 ` Stefan Monnier
2007-09-20 1:54 ` Dan Nicolaescu
1 sibling, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2007-09-19 13:45 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: Lennart Borgman (gmail), rms, Drew Adams, emacs-devel
> Here's my first try at doing this.
The change should not be in indent-according-to-mode, but in
indent-for-tab-command.
> lisp-mode needed changes because it
> binds TAB differently...
It simply shouldn't bind TAB. I've just fixed it on the trunk.
Stefan
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-19 5:11 ` Drew Adams
@ 2007-09-19 13:45 ` Stefan Monnier
2007-09-19 14:34 ` Drew Adams
0 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2007-09-19 13:45 UTC (permalink / raw)
To: Drew Adams; +Cc: emacs-devel
> 1. `indent-region' only indents lines that start within the region. There's
If TAB with an active region should indent the region it should do it by
calling indent-region.
Whether indent-region does the right thing or not or is another issue.
Stefan
^ permalink raw reply [flat|nested] 30+ messages in thread
* RE: TAB when the region is active
2007-09-19 13:45 ` Stefan Monnier
@ 2007-09-19 14:34 ` Drew Adams
0 siblings, 0 replies; 30+ messages in thread
From: Drew Adams @ 2007-09-19 14:34 UTC (permalink / raw)
To: emacs-devel
> > 1. `indent-region' only indents lines that start within the
> region. There's
>
> If TAB with an active region should indent the region it should do it by
> calling indent-region.
> Whether indent-region does the right thing or not or is another issue.
Maybe. Depends on what you intend the region for in this context, and what
you use it for in indent-region. The two are not necessarily the same.
I don't know whether indent-region DTRT in general, as I don't know exactly
what it was intended to do. I described some behavior that to me is not TRT
in this context, but perhaps that behavior is correct in other contexts.
(And I mentioned some behavior that looks like it might be a bug for the
general context also, but, again, I don't know the exact intention behind
indent-region.)
TRT for TAB with a region active can be different, depending on whether you
want to indent the complete _lines_ that are touched by a region or you want
to indent precisely the region (which indent-region seems to do). I can
imagine a use for each behavior. It is not because a function is named
"indent-region" that it is necessarily precisely what should be used for a
particular key binding (TAB) when the region is active.
I prefer the indent-each-line-in-the-region behavior for this context. You
might prefer the existing indent-region behavior or even some third
behavior. The existence of a function that does some indenting using the
region does not preclude the creation of a different function for a
different indenting behavior that also involves the region.
What I was describing was indenting complete lines, and using the region to,
in effect, identify those lines. That is the behavior that I would like to
see for TAB when a region is active. But that might not be TRT generally for
an indent-region command (I don't know). So, while it seems to make sense,
in general, that indent-region should be applicable when doing some
indenting that involves the region, I don't agree that it is the most
appropriate behavior in this specific case.
At least not its current behavior. And I'm not sure that the behavior that I
prefer in this context (indent all lines overlapping the region, in
succession) should replace the current behavior as the definition of
indent-region. I doubt it, in fact, as I imagine that there are good reasons
for the existing behavior.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-19 13:45 ` Stefan Monnier
@ 2007-09-20 1:54 ` Dan Nicolaescu
2007-09-20 13:52 ` Stefan Monnier
0 siblings, 1 reply; 30+ messages in thread
From: Dan Nicolaescu @ 2007-09-20 1:54 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Lennart Borgman (gmail), rms, Drew Adams, emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > Here's my first try at doing this.
>
> The change should not be in indent-according-to-mode, but in
> indent-for-tab-command.
If I do it like this:
*** indent.el 26 Jul 2007 10:17:33 -0700 1.68
--- indent.el 19 Sep 2007 18:29:56 -0700
***************
*** 98,104 ****
((memq indent-line-function '(indent-relative indent-relative-maybe))
(funcall indent-line-function))
(t ;; The normal case.
! (indent-according-to-mode))))
(defun insert-tab (&optional arg)
(let ((count (prefix-numeric-value arg)))
--- 101,110 ----
((memq indent-line-function '(indent-relative indent-relative-maybe))
(funcall indent-line-function))
(t ;; The normal case.
! (if (and transient-mark-mode mark-active
! (not (eq (region-beginning) (region-end))))
! (indent-region (region-beginning) (region-end))
! (indent-according-to-mode)))))
(defun insert-tab (&optional arg)
(let ((count (prefix-numeric-value arg)))
then indenting the region by pressing TAB does not work in c-mode
anymore (it did work in my first try).
Should c-mode also not bind TAB?
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-20 1:54 ` Dan Nicolaescu
@ 2007-09-20 13:52 ` Stefan Monnier
2007-09-22 1:00 ` Dan Nicolaescu
0 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2007-09-20 13:52 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: Lennart Borgman (gmail), rms, Drew Adams, emacs-devel
>> > Here's my first try at doing this.
>> The change should not be in indent-according-to-mode, but in
>> indent-for-tab-command.
> If I do it like this:
> *** indent.el 26 Jul 2007 10:17:33 -0700 1.68
> --- indent.el 19 Sep 2007 18:29:56 -0700
> ***************
> *** 98,104 ****
> ((memq indent-line-function '(indent-relative indent-relative-maybe))
> (funcall indent-line-function))
> (t ;; The normal case.
> ! (indent-according-to-mode))))
> (defun insert-tab (&optional arg)
> (let ((count (prefix-numeric-value arg)))
> --- 101,110 ----
> ((memq indent-line-function '(indent-relative indent-relative-maybe))
> (funcall indent-line-function))
> (t ;; The normal case.
> ! (if (and transient-mark-mode mark-active
> ! (not (eq (region-beginning) (region-end))))
> ! (indent-region (region-beginning) (region-end))
> ! (indent-according-to-mode)))))
Please don't use an `if' in the tail of a `cond': just place the condition
directly in the `cond'.
> (defun insert-tab (&optional arg)
> (let ((count (prefix-numeric-value arg)))
> then indenting the region by pressing TAB does not work in c-mode
> anymore (it did work in my first try).
Sure. Some modes use the default behavior of TAB (e.g. it obeys
tab-always-indent), others override it. Those who override it have their
reason to do it, so we may want to tell them about it, but we shouldn't
impose it.
Putting the code in indent-according-to-mode will introduce bugs in code
that calls it specifically to indent a single line. It is just the
wrong place.
> Should c-mode also not bind TAB?
That's up to the maintainer of c-mode.
Stefan
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-20 13:52 ` Stefan Monnier
@ 2007-09-22 1:00 ` Dan Nicolaescu
2007-09-24 0:07 ` Juri Linkov
0 siblings, 1 reply; 30+ messages in thread
From: Dan Nicolaescu @ 2007-09-22 1:00 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Lennart Borgman (gmail), rms, Drew Adams, emacs-devel
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.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-22 1:00 ` Dan Nicolaescu
@ 2007-09-24 0:07 ` Juri Linkov
2007-09-24 1:09 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 30+ messages in thread
From: Juri Linkov @ 2007-09-24 0:07 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: emacs-devel
> 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)
\f
(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)
\f
(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)))
+
\f
(defcustom default-justification 'left
"*Method of justifying text not otherwise specified.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 30+ messages in thread
* RE: TAB when the region is active
2007-09-24 0:07 ` Juri Linkov
@ 2007-09-24 1:09 ` Drew Adams
2007-09-24 1:15 ` Juri Linkov
2007-09-24 2:37 ` Dan Nicolaescu
2007-09-24 18:20 ` Richard Stallman
2 siblings, 1 reply; 30+ messages in thread
From: Drew Adams @ 2007-09-24 1:09 UTC (permalink / raw)
To: Juri Linkov, Dan Nicolaescu; +Cc: emacs-devel
> 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'.
I'm not so sure. There are several possibilities. A case could be made for
any of them to play the role you see for `fill-region':
. fill-region - Fill each paragraph in the region.
. fill-region-as-paragraph - Fill the region as one paragraph.
. fill-individual-paragraphs - Fill paragraphs of uniform
indentation within the region.
. fill-nonuniform-paragraphs - Fill paragraphs within the region,
allowing varying indentation within each.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-24 1:09 ` Drew Adams
@ 2007-09-24 1:15 ` Juri Linkov
2007-09-24 3:50 ` Stefan Monnier
2007-09-24 18:20 ` TAB when the region is active Richard Stallman
0 siblings, 2 replies; 30+ messages in thread
From: Juri Linkov @ 2007-09-24 1:15 UTC (permalink / raw)
To: Drew Adams; +Cc: Dan Nicolaescu, emacs-devel
>> 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'.
>
> I'm not so sure. There are several possibilities. A case could be made for
> any of them to play the role you see for `fill-region':
>
> . fill-region - Fill each paragraph in the region.
> . fill-region-as-paragraph - Fill the region as one paragraph.
>
> . fill-individual-paragraphs - Fill paragraphs of uniform
> indentation within the region.
>
> . fill-nonuniform-paragraphs - Fill paragraphs within the region,
> allowing varying indentation within each.
The last three are special cases of `fill-region' that are rarely used.
They can be invoked exactly as now, i.e. with M-x fill-region-as-paragraph RET
What I propose is to make it easier to call the most often used command
`fill-region' on the active region.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-24 0:07 ` Juri Linkov
2007-09-24 1:09 ` Drew Adams
@ 2007-09-24 2:37 ` Dan Nicolaescu
2007-09-24 18:20 ` Richard Stallman
2 siblings, 0 replies; 30+ messages in thread
From: Dan Nicolaescu @ 2007-09-24 2:37 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel
Juri Linkov <juri@jurta.org> writes:
> > 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.
It seems that binding TAB to c-indent-line-or-region might be
enough. I haven't tested this though...
> 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.
This patch might allow TAB to run indent-region for those
modes too:
*** indent.el 21 Sep 2007 18:37:51 -0700 1.69
--- indent.el 23 Sep 2007 19:20:24 -0700
***************
*** 95,108 ****
(or (> (current-column) (current-indentation))
(eq this-command last-command))))
(insert-tab arg))
- ;; Those functions are meant specifically for tabbing and not for
- ;; indenting, so we can't pass them to indent-according-to-mode.
- ((memq indent-line-function '(indent-relative indent-relative-maybe))
- (funcall indent-line-function))
;; The region is active, indent it.
((and transient-mark-mode mark-active
(not (eq (region-beginning) (region-end))))
(indent-region (region-beginning) (region-end)))
;; Indent the line.
(t
(indent-according-to-mode))))
--- 95,108 ----
(or (> (current-column) (current-indentation))
(eq this-command last-command))))
(insert-tab arg))
;; The region is active, indent it.
((and transient-mark-mode mark-active
(not (eq (region-beginning) (region-end))))
(indent-region (region-beginning) (region-end)))
+ ;; Those functions are meant specifically for tabbing and not for
+ ;; indenting, so we can't pass them to indent-according-to-mode.
+ ((memq indent-line-function '(indent-relative indent-relative-maybe))
+ (funcall indent-line-function))
;; Indent the line.
(t
(indent-according-to-mode))))
> 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'.
Good idea!
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-24 1:15 ` Juri Linkov
@ 2007-09-24 3:50 ` Stefan Monnier
2007-09-29 23:18 ` M-q when the region is active (Re: TAB when the region is active) Juri Linkov
2007-09-24 18:20 ` TAB when the region is active Richard Stallman
1 sibling, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2007-09-24 3:50 UTC (permalink / raw)
To: Juri Linkov; +Cc: Dan Nicolaescu, Drew Adams, emacs-devel
> The last three are special cases of `fill-region' that are rarely used.
> They can be invoked exactly as now, i.e. with M-x fill-region-as-paragraph
> RET
Actually I rarely if ever use fill-region whereas I use
fill-region-as-paragraph much more often. Typically the way this works is
that fill-paragraph doesn't do the right thing, so I use
fill-region-as-paragraph to tell Emacs exactly which part of the text
should be considered as a paragraph.
This is even worse with fill-region because while fill-paragraph can be
tuned via fill-paragraph-function, fill-region is 100% hard coded and the
major can't do anything about it. This is actually a bug, IMNSHO, which I'd
like to fix by introducing fill-paragraph-forward-function whose value would
default to forward-paragraph.
Stefan
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-24 0:07 ` Juri Linkov
2007-09-24 1:09 ` Drew Adams
2007-09-24 2:37 ` Dan Nicolaescu
@ 2007-09-24 18:20 ` Richard Stallman
2 siblings, 0 replies; 30+ messages in thread
From: Richard Stallman @ 2007-09-24 18:20 UTC (permalink / raw)
To: Juri Linkov; +Cc: dann, emacs-devel
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.
It sounds like we should fix C-M-\ in Text mode to do something useful,
then make TAB with a region do the same thing.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: TAB when the region is active
2007-09-24 1:15 ` Juri Linkov
2007-09-24 3:50 ` Stefan Monnier
@ 2007-09-24 18:20 ` Richard Stallman
1 sibling, 0 replies; 30+ messages in thread
From: Richard Stallman @ 2007-09-24 18:20 UTC (permalink / raw)
To: Juri Linkov; +Cc: dann, drew.adams, emacs-devel
What I propose is to make it easier to call the most often used command
`fill-region' on the active region.
I agree.
If you do it, please mention it in NEWS.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: M-q when the region is active (Re: TAB when the region is active)
2007-09-24 3:50 ` Stefan Monnier
@ 2007-09-29 23:18 ` Juri Linkov
2007-09-30 12:54 ` Richard Stallman
0 siblings, 1 reply; 30+ messages in thread
From: Juri Linkov @ 2007-09-29 23:18 UTC (permalink / raw)
To: Stefan Monnier; +Cc: dann, drew.adams, emacs-devel
> Actually I rarely if ever use fill-region whereas I use
> fill-region-as-paragraph much more often. Typically the way this works is
> that fill-paragraph doesn't do the right thing, so I use
> fill-region-as-paragraph to tell Emacs exactly which part of the text
> should be considered as a paragraph.
Most often I use `fill-region' to refill several separate paragraphs in
a selected chapter or the whole buffer.
> This is even worse with fill-region because while fill-paragraph can be
> tuned via fill-paragraph-function, fill-region is 100% hard coded and the
> major can't do anything about it. This is actually a bug, IMNSHO, which I'd
> like to fix by introducing fill-paragraph-forward-function whose value would
> default to forward-paragraph.
I discovered that some packages in the Emacs source tree already refer
to the function with the same name that exists in XEmacs. I looked at its
definition in XEmacs and found that it works exactly as I proposed: when
the region is active it calls `fill-region', otherwise `fill-paragraph'.
Is this a good enough reason to use `fill-region' on the active region,
and not other fill-related functions, for the sake of compatibility?
IMHO, it was a good decision to use `fill-region' in XEmacs. What do you think
about doing the same in Emacs together with your improvements in `fill-region'?
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: M-q when the region is active (Re: TAB when the region is active)
2007-09-29 23:18 ` M-q when the region is active (Re: TAB when the region is active) Juri Linkov
@ 2007-09-30 12:54 ` Richard Stallman
2007-10-06 22:43 ` M-$ when the region is active (Re: M-q " Juri Linkov
0 siblings, 1 reply; 30+ messages in thread
From: Richard Stallman @ 2007-09-30 12:54 UTC (permalink / raw)
To: Juri Linkov; +Cc: dann, monnier, drew.adams, emacs-devel
Is this a good enough reason to use `fill-region' on the active region,
and not other fill-related functions, for the sake of compatibility?
I think it is the right decision, even aside from compatibility.
Would someone please do this in the trunk?
^ permalink raw reply [flat|nested] 30+ messages in thread
* M-$ when the region is active (Re: M-q when the region is active)
2007-09-30 12:54 ` Richard Stallman
@ 2007-10-06 22:43 ` Juri Linkov
0 siblings, 0 replies; 30+ messages in thread
From: Juri Linkov @ 2007-10-06 22:43 UTC (permalink / raw)
To: rms; +Cc: emacs-devel
> Is this a good enough reason to use `fill-region' on the active region,
> and not other fill-related functions, for the sake of compatibility?
>
> I think it is the right decision, even aside from compatibility.
> Would someone please do this in the trunk?
Done.
I have the last proposal for another keybinding on the active region
(I see no other useful cases at the moment).
ispell-region is a useful command, but it is inconvenient to call.
Selecting a region in transient-mark-mode and typing M-$ (ispell-word)
will improve this by starting spell-checking on the active region.
In the patch below I managed to add a new condition without reindenting
the large body of the function `ispell-word'. I also fixed messages
displayed at the start and end of the spell-checking to be the same.
They now differ only by the suffix "..." and "done".
PS: I know that flyspell makes ispell commands unnecessary, but this
proposal is intended for users who don't use flyspell.
Index: lisp/textmodes/ispell.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/textmodes/ispell.el,v
retrieving revision 1.213
diff -c -r1.213 ispell.el
*** lisp/textmodes/ispell.el 13 Aug 2007 13:40:47 -0000 1.213
--- lisp/textmodes/ispell.el 6 Oct 2007 22:38:01 -0000
***************
*** 1594,1601 ****
quit spell session exited."
(interactive (list ispell-following-word ispell-quietly current-prefix-arg))
! (if continue
! (ispell-continue)
(ispell-maybe-find-aspell-dictionaries)
(ispell-accept-buffer-local-defs) ; use the correct dictionary
(let ((cursor-location (point)) ; retain cursor location
--- 1594,1605 ----
quit spell session exited."
(interactive (list ispell-following-word ispell-quietly current-prefix-arg))
! (cond
! ((and transient-mark-mode mark-active
! (not (eq (region-beginning) (region-end))))
! (ispell-region (region-beginning) (region-end)))
! (continue (ispell-continue))
! (t
(ispell-maybe-find-aspell-dictionaries)
(ispell-accept-buffer-local-defs) ; use the correct dictionary
(let ((cursor-location (point)) ; retain cursor location
***************
*** 1690,1696 ****
;; NB: Cancels ispell-quit incorrectly if called from ispell-region
(if ispell-quit (setq ispell-quit nil replace 'quit))
(goto-char cursor-location) ; return to original location
! replace)))
(defun ispell-get-word (following &optional extra-otherchars)
--- 1694,1700 ----
;; NB: Cancels ispell-quit incorrectly if called from ispell-region
(if ispell-quit (setq ispell-quit nil replace 'quit))
(goto-char cursor-location) ; return to original location
! replace))))
(defun ispell-get-word (following &optional extra-otherchars)
***************
*** 2683,2689 ****
(rstart (make-marker)))
(unwind-protect
(save-excursion
! (message "Spell checking %s using %s with %s dictionary..."
(if (and (= reg-start (point-min)) (= reg-end (point-max)))
(buffer-name) "region")
(file-name-nondirectory ispell-program-name)
--- 2687,2693 ----
(rstart (make-marker)))
(unwind-protect
(save-excursion
! (message "Spell-checking %s using %s with %s dictionary..."
(if (and (= reg-start (point-min)) (= reg-end (point-max)))
(buffer-name) "region")
(file-name-nondirectory ispell-program-name)
***************
*** 2782,2788 ****
(if (not recheckp) (set-marker ispell-region-end nil))
;; Only save if successful exit.
(ispell-pdict-save ispell-silently-savep)
! (message "Spell-checking using %s with %s dictionary done"
(file-name-nondirectory ispell-program-name)
(or ispell-current-dictionary "default"))))))
--- 2786,2794 ----
(if (not recheckp) (set-marker ispell-region-end nil))
;; Only save if successful exit.
(ispell-pdict-save ispell-silently-savep)
! (message "Spell-checking %s using %s with %s dictionary done"
! (if (and (= reg-start (point-min)) (= reg-end (point-max)))
! (buffer-name) "region")
(file-name-nondirectory ispell-program-name)
(or ispell-current-dictionary "default"))))))
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2007-10-06 22:43 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-14 21:59 TAB when the region is active Dan Nicolaescu
2007-09-16 5:35 ` Richard Stallman
2007-09-17 4:09 ` Dan Nicolaescu
2007-09-17 22:24 ` Richard Stallman
2007-09-17 22:40 ` Lennart Borgman (gmail)
2007-09-17 22:47 ` Drew Adams
2007-09-17 23:28 ` Dan Nicolaescu
2007-09-19 3:42 ` Dan Nicolaescu
2007-09-19 5:11 ` Drew Adams
2007-09-19 13:45 ` Stefan Monnier
2007-09-19 14:34 ` Drew Adams
2007-09-19 13:45 ` Stefan Monnier
2007-09-20 1:54 ` Dan Nicolaescu
2007-09-20 13:52 ` Stefan Monnier
2007-09-22 1:00 ` Dan Nicolaescu
2007-09-24 0:07 ` Juri Linkov
2007-09-24 1:09 ` Drew Adams
2007-09-24 1:15 ` Juri Linkov
2007-09-24 3:50 ` Stefan Monnier
2007-09-29 23:18 ` M-q when the region is active (Re: TAB when the region is active) Juri Linkov
2007-09-30 12:54 ` Richard Stallman
2007-10-06 22:43 ` M-$ when the region is active (Re: M-q " Juri Linkov
2007-09-24 18:20 ` TAB when the region is active Richard Stallman
2007-09-24 2:37 ` Dan Nicolaescu
2007-09-24 18:20 ` Richard Stallman
2007-09-17 23:13 ` Dan Nicolaescu
2007-09-16 18:48 ` Lennart Borgman
2007-09-16 19:17 ` Paul Pogonyshev
2007-09-16 20:32 ` Drew Adams
2007-09-17 3:59 ` Richard Stallman
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.