* C-u prefix behavior of TAB broken
@ 2007-12-16 22:07 Miles Bader
2007-12-17 12:48 ` martin rudalics
0 siblings, 1 reply; 38+ messages in thread
From: Miles Bader @ 2007-12-16 22:07 UTC (permalink / raw)
To: emacs-devel
Until the recent changes to the default TAB command, it used to be that
using a C-u prefix with TAB (in a programming language mode) would
indent the entire following form to reflect the change in indentation
(where the form selected was whatever the sexp commands would select --
e.g. an entire brace-delimited code block).
This was a very handy feature, but doesn't work anymore.
For instance if you place the cursor before "(when" in the following
elisp code:
(defun test (flag)
(when flag
(format "hello")))
and hit TAB, the result _used_ to be:
(defun test (flag)
(when flag
(format "hello")))
But now it just gives you:
(defun test (flag)
(when flag
(format "hello")))
[I don't know exactly _where_ this feature was implemented, but it
worked at least in lisp mode and the various C related modes.]
Thanks,
-Miles
--
"Though they may have different meanings, the cries of 'Yeeeee-haw!' and
'Allahu akbar!' are, in spirit, not actually all that different."
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-16 22:07 C-u prefix behavior of TAB broken Miles Bader
@ 2007-12-17 12:48 ` martin rudalics
2007-12-17 14:27 ` Miles Bader
0 siblings, 1 reply; 38+ messages in thread
From: martin rudalics @ 2007-12-17 12:48 UTC (permalink / raw)
To: Miles Bader; +Cc: emacs-devel
> Until the recent changes to the default TAB command, it used to be that
> using a C-u prefix with TAB (in a programming language mode) would
> indent the entire following form to reflect the change in indentation
> (where the form selected was whatever the sexp commands would select --
> e.g. an entire brace-delimited code block).
>
> This was a very handy feature, but doesn't work anymore.
This never worked for me. I had:
With argument, indent any additional lines of the same expression
rigidly along with this one.
> [I don't know exactly _where_ this feature was implemented, but it
> worked at least in lisp mode and the various C related modes.]
If you ever find out where you got this code from please post the source
here. I'd like to bind it to TAB TAB.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-17 12:48 ` martin rudalics
@ 2007-12-17 14:27 ` Miles Bader
2007-12-17 19:03 ` martin rudalics
2007-12-18 2:24 ` Richard Stallman
0 siblings, 2 replies; 38+ messages in thread
From: Miles Bader @ 2007-12-17 14:27 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel
martin rudalics <rudalics@gmx.at> writes:
> This never worked for me. I had:
>
> With argument, indent any additional lines of the same expression
> rigidly along with this one.
I'm not sure what you mean... maybe my explanation was poor, but the
above is what I'm referring to.
Anyway, that feature is now broken.
-Miles
--
I'm beginning to think that life is just one long Yoko Ono album; no rhyme
or reason, just a lot of incoherent shrieks and then it's over. --Ian Wolff
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-17 14:27 ` Miles Bader
@ 2007-12-17 19:03 ` martin rudalics
2007-12-21 0:20 ` Stefan Monnier
2007-12-18 2:24 ` Richard Stallman
1 sibling, 1 reply; 38+ messages in thread
From: martin rudalics @ 2007-12-17 19:03 UTC (permalink / raw)
To: Miles Bader; +Cc: emacs-devel
> I'm not sure what you mean... maybe my explanation was poor, but the
> above is what I'm referring to.
I thought you had a less rigid version of that.
> Anyway, that feature is now broken.
FWIW in lisp-mode it's due to that change:
2007-09-19 Stefan Monnier <monnier@iro.umontreal.ca>
...
* emacs-lisp/lisp-mode.el (lisp-mode-shared-map): Use the default TAB
binding, so tab-always-indent works right.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-17 19:03 ` martin rudalics
@ 2007-12-21 0:20 ` Stefan Monnier
2007-12-21 19:49 ` Richard Stallman
0 siblings, 1 reply; 38+ messages in thread
From: Stefan Monnier @ 2007-12-21 0:20 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel, Miles Bader
>> I'm not sure what you mean... maybe my explanation was poor, but the
>> above is what I'm referring to.
> I thought you had a less rigid version of that.
>> Anyway, that feature is now broken.
> FWIW in lisp-mode it's due to that change:
> 2007-09-19 Stefan Monnier <monnier@iro.umontreal.ca>
> ...
> * emacs-lisp/lisp-mode.el (lisp-mode-shared-map): Use the default TAB
> binding, so tab-always-indent works right.
It may be the superficial reason for it, but it shouldn't be the root
cause for it: indent-for-tab-command used to pass the C-u prefix to the
indent-line-function.
This said, IMNSHO the feature we're talking about shouldn't be implement
in lisp-mode and c-mode but directly generically in
indent-for-tab-command.
I use the following code in my local version of indent-for-tab-command
for that purpose:
(cond
[...]
(arg
(let ((old-indent (current-indentation)))
(if (eq (indent-according-to-mode) 'noindent)
(funcall (default-value 'indent-line-function)))
(let ((new-indent (current-indentation))
(beg (line-beginning-position 2))
(end (save-excursion (beginning-of-line)
(forward-sexp 1)
(point))))
(when (and (> end beg) (/= new-indent old-indent))
(indent-code-rigidly beg end (- new-indent old-indent))))))
[...])
Stefan
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-21 0:20 ` Stefan Monnier
@ 2007-12-21 19:49 ` Richard Stallman
2007-12-22 0:11 ` Miles Bader
2007-12-26 3:00 ` Miles Bader
0 siblings, 2 replies; 38+ messages in thread
From: Richard Stallman @ 2007-12-21 19:49 UTC (permalink / raw)
To: Stefan Monnier; +Cc: rudalics, miles, emacs-devel
This said, IMNSHO the feature we're talking about shouldn't be implement
in lisp-mode and c-mode but directly generically in
indent-for-tab-command.
If that works, by all means do it.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-21 19:49 ` Richard Stallman
@ 2007-12-22 0:11 ` Miles Bader
2007-12-22 9:28 ` martin rudalics
2007-12-26 3:00 ` Miles Bader
1 sibling, 1 reply; 38+ messages in thread
From: Miles Bader @ 2007-12-22 0:11 UTC (permalink / raw)
To: Stefan Monnier; +Cc: rudalics, rms, emacs-devel
Richard Stallman <rms@gnu.org> writes:
> This said, IMNSHO the feature we're talking about shouldn't be implement
> in lisp-mode and c-mode but directly generically in
> indent-for-tab-command.
>
> If that works, by all means do it.
I'd certainly be grateful!
[I didn't realize I used it so much (on the face of it, it seems like a
rather obscure bit of functionality), but I find my fingers keep trying
to invoke it, and I keep being surprised when it doesn't work... ]
-Miles
--
What the fuck do white people have to be blue about!? Banana Republic ran
out of Khakis? The Espresso Machine is jammed? Hootie and The Blowfish are
breaking up??! Shit, white people oughtta understand, their job is to GIVE
people the blues, not to get them! -- George Carlin
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 0:11 ` Miles Bader
@ 2007-12-22 9:28 ` martin rudalics
2007-12-22 13:48 ` Miles Bader
` (2 more replies)
0 siblings, 3 replies; 38+ messages in thread
From: martin rudalics @ 2007-12-22 9:28 UTC (permalink / raw)
To: Miles Bader; +Cc: emacs-devel, Stefan Monnier, rms
[-- Attachment #1: Type: text/plain, Size: 1002 bytes --]
>> This said, IMNSHO the feature we're talking about shouldn't be implement
>> in lisp-mode and c-mode but directly generically in
>> indent-for-tab-command.
>>
>>If that works, by all means do it.
FWIW all indent-line-functions with the exception of `lisp-indent-line'
either don't have arguments or, like `c-indent-line', `f90-indent-line',
and `(c)perl-indent-line' expect completely different arguments here.
Hence a generic solution seems hardly practicable.
For the case a prefix argument is given and the region is not active, we
could try to set the region around the smallest containing form and call
`indent-region' on that. But that would be a different feature.
> I'd certainly be grateful!
>
> [I didn't realize I used it so much (on the face of it, it seems like a
> rather obscure bit of functionality), but I find my fingers keep trying
> to invoke it, and I keep being surprised when it doesn't work... ]
For `lisp-indent-line' I can offer the attached patch.
[-- Attachment #2: lisp-mode.patch --]
[-- Type: text/plain, Size: 803 bytes --]
*** lisp-mode.el.~1.209.~ Tue Oct 9 11:52:54 2007
--- lisp-mode.el Sat Dec 22 09:55:52 2007
***************
*** 821,827 ****
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))
;; If desired, shift remaining lines of expression the same amount.
! (and whole-exp (not (zerop shift-amt))
(save-excursion
(goto-char beg)
(forward-sexp 1)
--- 821,831 ----
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))
;; If desired, shift remaining lines of expression the same amount.
! (and (or whole-exp
! (and current-prefix-arg
! (or (not transient-mark-mode)
! (not mark-active))))
! (not (zerop shift-amt))
(save-excursion
(goto-char beg)
(forward-sexp 1)
[-- Attachment #3: 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] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 9:28 ` martin rudalics
@ 2007-12-22 13:48 ` Miles Bader
2007-12-22 17:41 ` martin rudalics
2007-12-22 21:08 ` Richard Stallman
2007-12-23 0:51 ` Stefan Monnier
2 siblings, 1 reply; 38+ messages in thread
From: Miles Bader @ 2007-12-22 13:48 UTC (permalink / raw)
To: martin rudalics; +Cc: Stefan Monnier, rms, emacs-devel
martin rudalics <rudalics@gmx.at> writes:
> For the case a prefix argument is given and the region is not active, we
> could try to set the region around the smallest containing form and call
> `indent-region' on that. But that would be a different feature.
Can't indent-for-tab-command simply, if there's a prefix argument given,
rigidly indent the following sexp by the change in indentation? That
doesn't seem hard at all, and matches the behavior I remember (perhaps
there are corner cases where it would differ, but I don't think I know
about them...).
For instance, the following isn't the most elegant code, but it seems to
do the right thing:
--- orig/lisp/indent.el
+++ mod/lisp/indent.el
@@ -99,13 +99,26 @@
(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))
- ;; Indent the line.
(t
- (indent-according-to-mode))))
+ (let ((end-marker (and arg (save-excursion (forward-sexp) (point-marker))))
+ (old-indent (current-indentation)))
+
+ ;; Those functions are meant specifically for tabbing and not for
+ ;; indenting, so we can't pass them to indent-according-to-mode.
+ (if (memq indent-line-function '(indent-relative indent-relative-maybe))
+ (funcall indent-line-function)
+ ;; Indent the line.
+ (indent-according-to-mode))
+
+ ;; If a prefix argument was given, rigidly indent the following
+ ;; sexp to match the change in the current line's indentation.
+ ;;
+ (when arg
+ (let ((indentation-change (- (current-indentation) old-indent)))
+ (save-excursion
+ (forward-line 1)
+ (when (< (point) end-marker)
+ (indent-rigidly (point) end-marker indentation-change)))))))))
(defun insert-tab (&optional arg)
(let ((count (prefix-numeric-value arg)))
-Miles
--
"An atheist doesn't have to be someone who thinks he has a proof that there
can't be a god. He only has to be someone who believes that the evidence
on the God question is at a similar level to the evidence on the werewolf
question." [John McCarthy]
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 13:48 ` Miles Bader
@ 2007-12-22 17:41 ` martin rudalics
2007-12-22 19:52 ` Miles Bader
2007-12-23 0:55 ` Stefan Monnier
0 siblings, 2 replies; 38+ messages in thread
From: martin rudalics @ 2007-12-22 17:41 UTC (permalink / raw)
To: Miles Bader; +Cc: Stefan Monnier, rms, emacs-devel
> Can't indent-for-tab-command simply, if there's a prefix argument given,
> rigidly indent the following sexp by the change in indentation? That
> doesn't seem hard at all, and matches the behavior I remember (perhaps
> there are corner cases where it would differ, but I don't think I know
> about them...).
For `tab-always-indent' t it might make sense to do `beginning-of-line'
before the `forward-sexp'. Otherwise it should work wherever
`forward-sexp' behaves reasonably. BTW, isn't
((memq indent-line-function '(indent-relative indent-relative-maybe))
(funcall indent-line-function))
;; Indent the line.
(t
(indent-according-to-mode))
semantically equivalent to
(t
(funcall indent-line-function))
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 17:41 ` martin rudalics
@ 2007-12-22 19:52 ` Miles Bader
2007-12-22 22:35 ` martin rudalics
2007-12-23 0:55 ` Stefan Monnier
1 sibling, 1 reply; 38+ messages in thread
From: Miles Bader @ 2007-12-22 19:52 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel, Stefan Monnier, rms
martin rudalics <rudalics@gmx.at> writes:
> For `tab-always-indent' t it might make sense to do `beginning-of-line'
> before the `forward-sexp'.
True. It doesn't reach that code at all if tab-always-indent is nil and
the point is not in the indentation, so I think it can just always move
to the start of the line before calling forward-sexp.
> BTW, isn't
>
> ((memq indent-line-function '(indent-relative indent-relative-maybe))
> (funcall indent-line-function))
> ;; Indent the line.
> (t
> (indent-according-to-mode))
>
> semantically equivalent to
>
> (t
> (funcall indent-line-function))
Indeed yes! That's a nice simplification...
I fixed some other little problems (e.g. it should have been using "P"
[raw-prefix] in the interactive spec), so here's the current patch:
--- orig/lisp/indent.el
+++ mod/lisp/indent.el
@@ -86,10 +86,10 @@
indent the region.
The function actually called to indent the line is determined by the value of
`indent-line-function'."
- (interactive "p")
+ (interactive "P")
(cond
;; The region is active, indent it.
- ((and arg transient-mark-mode mark-active
+ ((and transient-mark-mode mark-active
(not (eq (region-beginning) (region-end))))
(indent-region (region-beginning) (region-end)))
((or ;; indent-to-left-margin is only meant for indenting,
@@ -99,13 +99,26 @@
(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))
- ;; Indent the line.
(t
- (indent-according-to-mode))))
+ (let ((end-marker
+ (and arg
+ (save-excursion
+ (forward-line 0) (forward-sexp) (point-marker))))
+ (old-indent
+ (current-indentation)))
+
+ ;; Indent the line.
+ (funcall indent-line-function)
+
+ ;; If a prefix argument was given, rigidly indent the following
+ ;; sexp to match the change in the current line's indentation.
+ ;;
+ (when arg
+ (let ((indentation-change (- (current-indentation) old-indent)))
+ (save-excursion
+ (forward-line 1)
+ (when (< (point) end-marker)
+ (indent-rigidly (point) end-marker indentation-change)))))))))
(defun insert-tab (&optional arg)
(let ((count (prefix-numeric-value arg)))
--
Ich bin ein Virus. Mach' mit und kopiere mich in Deine .signature.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 19:52 ` Miles Bader
@ 2007-12-22 22:35 ` martin rudalics
2007-12-22 22:59 ` Miles Bader
0 siblings, 1 reply; 38+ messages in thread
From: martin rudalics @ 2007-12-22 22:35 UTC (permalink / raw)
To: Miles Bader; +Cc: emacs-devel, Stefan Monnier, rms
> + (let ((indentation-change (- (current-indentation) old-indent)))
`lisp-indent-line' quits here when `indentation-change' equals zero.
> + (save-excursion
> + (forward-line 1)
> + (when (< (point) end-marker)
> + (indent-rigidly (point) end-marker indentation-change)))))))))
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 22:35 ` martin rudalics
@ 2007-12-22 22:59 ` Miles Bader
2008-02-24 19:05 ` Juri Linkov
0 siblings, 1 reply; 38+ messages in thread
From: Miles Bader @ 2007-12-22 22:59 UTC (permalink / raw)
To: martin rudalics; +Cc: Stefan Monnier, rms, emacs-devel
martin rudalics <rudalics@gmx.at> writes:
>> + (let ((indentation-change (- (current-indentation) old-indent)))
>
> `lisp-indent-line' quits here when `indentation-change' equals zero.
Good point (fixed below).
-Miles
--- orig/lisp/indent.el
+++ mod/lisp/indent.el
@@ -86,10 +86,10 @@
indent the region.
The function actually called to indent the line is determined by the value of
`indent-line-function'."
- (interactive "p")
+ (interactive "P")
(cond
;; The region is active, indent it.
- ((and arg transient-mark-mode mark-active
+ ((and transient-mark-mode mark-active
(not (eq (region-beginning) (region-end))))
(indent-region (region-beginning) (region-end)))
((or ;; indent-to-left-margin is only meant for indenting,
@@ -99,13 +99,27 @@
(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))
- ;; Indent the line.
(t
- (indent-according-to-mode))))
+ (let ((end-marker
+ (and arg
+ (save-excursion
+ (forward-line 0) (forward-sexp) (point-marker))))
+ (old-indent
+ (current-indentation)))
+
+ ;; Indent the line.
+ (funcall indent-line-function)
+
+ ;; If a prefix argument was given, rigidly indent the following
+ ;; sexp to match the change in the current line's indentation.
+ ;;
+ (when arg
+ (let ((indentation-change (- (current-indentation) old-indent)))
+ (unless (zerop indentation-change)
+ (save-excursion
+ (forward-line 1)
+ (when (< (point) end-marker)
+ (indent-rigidly (point) end-marker indentation-change))))))))))
(defun insert-tab (&optional arg)
(let ((count (prefix-numeric-value arg)))
--
The car has become... an article of dress without which we feel uncertain,
unclad, and incomplete. [Marshall McLuhan, Understanding Media, 1964]
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 22:59 ` Miles Bader
@ 2008-02-24 19:05 ` Juri Linkov
2008-02-24 19:26 ` Miles Bader
0 siblings, 1 reply; 38+ messages in thread
From: Juri Linkov @ 2008-02-24 19:05 UTC (permalink / raw)
To: Miles Bader; +Cc: emacs-devel
> + ;; If a prefix argument was given, rigidly indent the following
> + ;; sexp to match the change in the current line's indentation.
> + (when arg
> + (let ((indentation-change (- (current-indentation) old-indent)))
> + (unless (zerop indentation-change)
> + (save-excursion
> + (forward-line 1)
> + (when (< (point) end-marker)
> + (indent-rigidly (point) end-marker indentation-change))))))))))
I have bound a key to the command that calls `indent-for-tab-command'
with a prefix argument, and when I accidently type it a close parenthesis,
it fails with the error "Containing expression ends prematurely".
I think it would be better not to fail at such places, and just indent
the current line without indenting the following sexp.
The following patch fixes this. Any better ideas?
Index: lisp/indent.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/indent.el,v
retrieving revision 1.76
diff -u -r1.76 indent.el
--- lisp/indent.el 8 Jan 2008 20:44:48 -0000 1.76
+++ lisp/indent.el 24 Feb 2008 19:04:32 -0000
@@ -29,6 +29,8 @@
;;; Code:
+(eval-when-compile (require 'cl)) ;; for `ignore-errors'
+
(defgroup indent nil
"Indentation commands."
:group 'editing)
@@ -109,7 +111,7 @@
(let ((end-marker
(and arg
(save-excursion
- (forward-line 0) (forward-sexp) (point-marker))))
+ (forward-line 0) (ignore-errors (forward-sexp)) (point-marker))))
(old-indent
(current-indentation)))
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2008-02-24 19:05 ` Juri Linkov
@ 2008-02-24 19:26 ` Miles Bader
2008-02-24 19:40 ` Juri Linkov
0 siblings, 1 reply; 38+ messages in thread
From: Miles Bader @ 2008-02-24 19:26 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel
Juri Linkov <juri@jurta.org> writes:
> I have bound a key to the command that calls `indent-for-tab-command'
> with a prefix argument, and when I accidently type it a close parenthesis,
> it fails with the error "Containing expression ends prematurely".
That sounds correct to me...
> I think it would be better not to fail at such places, and just indent
> the current line without indenting the following sexp.
Wouldn't it be a bit more elegant for you to change your command to
do something like:
(condition-case err (indent-for-tab-command t)
(error (indent-for-tab-command)))
?
-Miles
--
Ich bin ein Virus. Mach' mit und kopiere mich in Deine .signature.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2008-02-24 19:26 ` Miles Bader
@ 2008-02-24 19:40 ` Juri Linkov
2008-02-25 2:56 ` Miles Bader
0 siblings, 1 reply; 38+ messages in thread
From: Juri Linkov @ 2008-02-24 19:40 UTC (permalink / raw)
To: Miles Bader; +Cc: emacs-devel
>> I have bound a key to the command that calls `indent-for-tab-command'
>> with a prefix argument, and when I accidently type it a close parenthesis,
>> it fails with the error "Containing expression ends prematurely".
>
> That sounds correct to me...
This is correct, but I thought this is not very useful.
>> I think it would be better not to fail at such places, and just indent
>> the current line without indenting the following sexp.
>
> Wouldn't it be a bit more elegant for you to change your command to
> do something like:
>
> (condition-case err (indent-for-tab-command t)
> (error (indent-for-tab-command)))
This is not a problem for me, but I doubted that displaying an error message
would be useful for someone who types `C-u TAB' at the wrong place.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2008-02-24 19:40 ` Juri Linkov
@ 2008-02-25 2:56 ` Miles Bader
0 siblings, 0 replies; 38+ messages in thread
From: Miles Bader @ 2008-02-25 2:56 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel
Juri Linkov <juri@jurta.org> writes:
> This is correct, but I thought this is not very useful.
>
>> (condition-case err (indent-for-tab-command t)
>> (error (indent-for-tab-command)))
>
> This is not a problem for me, but I doubted that displaying an error message
> would be useful for someone who types `C-u TAB' at the wrong place.
I dunno, I'd think if someone types C-u before TAB, they do so
intentionally, thinking there's a balanced expression following, and
would like to know if something's screwy.
In the example you gave it's really obvious what the problem is, but
what if there's actually a non-trivial unbalanced expresison following?
It seems useful to give an error that says it can't find a balanced
expression rather than silently ignoring the C-u in that case...
E.g.:
(hello [
world)
The error message could be a bit more friendly though...
-Miles
--
Love is a snowmobile racing across the tundra. Suddenly it flips over,
pinning you underneath. At night the ice weasels come. --Nietzsche
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 17:41 ` martin rudalics
2007-12-22 19:52 ` Miles Bader
@ 2007-12-23 0:55 ` Stefan Monnier
2007-12-23 1:39 ` Miles Bader
1 sibling, 1 reply; 38+ messages in thread
From: Stefan Monnier @ 2007-12-23 0:55 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel, rms, Miles Bader
>> Can't indent-for-tab-command simply, if there's a prefix argument given,
>> rigidly indent the following sexp by the change in indentation? That
>> doesn't seem hard at all, and matches the behavior I remember (perhaps
>> there are corner cases where it would differ, but I don't think I know
>> about them...).
> For `tab-always-indent' t it might make sense to do `beginning-of-line'
> before the `forward-sexp'. Otherwise it should work wherever
> `forward-sexp' behaves reasonably. BTW, isn't
> ((memq indent-line-function '(indent-relative indent-relative-maybe))
> (funcall indent-line-function))
> ;; Indent the line.
> (t
> (indent-according-to-mode))
> semantically equivalent to
> (t
> (funcall indent-line-function))
No, it's not: check the definition of indent-according-to-mode.
The difference is to distinguish between the case where the user hits
TAB (and hence wants some kind of effect) as opposed to when
line-indentation is done non-interactively (e.g. by skeleton).
Stefan
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-23 0:55 ` Stefan Monnier
@ 2007-12-23 1:39 ` Miles Bader
2007-12-23 21:49 ` Stefan Monnier
0 siblings, 1 reply; 38+ messages in thread
From: Miles Bader @ 2007-12-23 1:39 UTC (permalink / raw)
To: Stefan Monnier; +Cc: martin rudalics, rms, emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> Can't indent-for-tab-command simply, if there's a prefix argument given,
>>> rigidly indent the following sexp by the change in indentation? That
>>> doesn't seem hard at all, and matches the behavior I remember (perhaps
>>> there are corner cases where it would differ, but I don't think I know
>>> about them...).
>
>> For `tab-always-indent' t it might make sense to do `beginning-of-line'
>> before the `forward-sexp'. Otherwise it should work wherever
>> `forward-sexp' behaves reasonably. BTW, isn't
>
>> ((memq indent-line-function '(indent-relative indent-relative-maybe))
>> (funcall indent-line-function))
>> ;; Indent the line.
>> (t
>> (indent-according-to-mode))
>
>> semantically equivalent to
>
>> (t
>> (funcall indent-line-function))
>
> No, it's not: check the definition of indent-according-to-mode.
>
> The difference is to distinguish between the case where the user hits
> TAB (and hence wants some kind of effect) as opposed to when
> line-indentation is done non-interactively (e.g. by skeleton).
>
> Stefan
But indent-according-to-mode is defined like this:
(defun indent-according-to-mode ()
....
(if (memq indent-line-function
'(indent-relative indent-relative-maybe))
... do some stuff ...
;; The normal case.
(funcall indent-line-function)))
So this:
(cond
...
((memq indent-line-function '(indent-relative indent-relative-maybe))
(funcall indent-line-function))
;; Indent the line.
(t
(indent-according-to-mode))
Is equivalent to this:
(cond
...
((memq indent-line-function '(indent-relative indent-relative-maybe))
(funcall indent-line-function))
;; Indent the line.
(t
(if (memq indent-line-function
'(indent-relative indent-relative-maybe))
... do some stuff ...
;; The normal case.
(funcall indent-line-function)))
and since the first cond branch catches the same cases that the `if'
catches, it will always use the `else' part, meaning it's actually:
(cond
...
((memq indent-line-function '(indent-relative indent-relative-maybe))
(funcall indent-line-function))
;; Indent the line.
(t
(funcall indent-line-function)))
Which of course is the same as:
(funcall indent-line-function)
-Miles
--
Occam's razor split hairs so well, I bought the whole argument!
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 9:28 ` martin rudalics
2007-12-22 13:48 ` Miles Bader
@ 2007-12-22 21:08 ` Richard Stallman
2007-12-22 22:08 ` martin rudalics
2007-12-23 0:51 ` Stefan Monnier
2 siblings, 1 reply; 38+ messages in thread
From: Richard Stallman @ 2007-12-22 21:08 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel, monnier, miles
FWIW all indent-line-functions with the exception of `lisp-indent-line'
either don't have arguments or, like `c-indent-line', `f90-indent-line',
and `(c)perl-indent-line' expect completely different arguments here.
Hence a generic solution seems hardly practicable.
Could you name one or two, so I can take a look and see specifically what
you mean?
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 21:08 ` Richard Stallman
@ 2007-12-22 22:08 ` martin rudalics
2007-12-23 21:11 ` Richard Stallman
0 siblings, 1 reply; 38+ messages in thread
From: martin rudalics @ 2007-12-22 22:08 UTC (permalink / raw)
To: rms; +Cc: miles, monnier, emacs-devel
> FWIW all indent-line-functions with the exception of `lisp-indent-line'
> either don't have arguments or, like `c-indent-line', `f90-indent-line',
> and `(c)perl-indent-line' expect completely different arguments here.
> Hence a generic solution seems hardly practicable.
>
> Could you name one or two, so I can take a look and see specifically what
> you mean?
I meant that
(defun lisp-indent-line (&optional whole-exp)
takes one optional argument `whole-exp' that implements the feature.
(defun c-indent-line (&optional syntax quiet ignore-point-pos)
takes three completely unrelated arguments and won't implement the
feature.
(defun python-indent-line ()
takes no argument at all and won't implement the feature either.
All this based on the assumption that `indent-for-tab-command' with a
prefix argument would pass something like `whole-exp' down to the
indent-line function of the major mode and have the latter do the job.
Miles elegantly side-stepped the issue in his patch by implementing the
feature within `indent-for-tab-command' so my argument is void.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 22:08 ` martin rudalics
@ 2007-12-23 21:11 ` Richard Stallman
2007-12-23 21:44 ` martin rudalics
0 siblings, 1 reply; 38+ messages in thread
From: Richard Stallman @ 2007-12-23 21:11 UTC (permalink / raw)
To: martin rudalics; +Cc: miles, monnier, emacs-devel
I meant that
(defun lisp-indent-line (&optional whole-exp)
takes one optional argument `whole-exp' that implements the feature.
(defun c-indent-line (&optional syntax quiet ignore-point-pos)
takes three completely unrelated arguments and won't implement the
feature.
Nonetheless, C-u TAB seems to work correctly in C mode. Whatever
differences there may be in the structure of the code in C mode, this
feature works, and it should continue to work.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-23 21:11 ` Richard Stallman
@ 2007-12-23 21:44 ` martin rudalics
2007-12-24 21:55 ` Richard Stallman
0 siblings, 1 reply; 38+ messages in thread
From: martin rudalics @ 2007-12-23 21:44 UTC (permalink / raw)
To: rms; +Cc: miles, monnier, emacs-devel
> Nonetheless, C-u TAB seems to work correctly in C mode.
With Emacs -Q C-u TAB doesn't behave differently from TAB in C mode
on my system. Can you give me some guidance on how to obtain the
"correct" behavior you mention?
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-23 21:44 ` martin rudalics
@ 2007-12-24 21:55 ` Richard Stallman
2007-12-24 22:33 ` martin rudalics
0 siblings, 1 reply; 38+ messages in thread
From: Richard Stallman @ 2007-12-24 21:55 UTC (permalink / raw)
To: martin rudalics; +Cc: miles, monnier, emacs-devel
With Emacs -Q C-u TAB doesn't behave differently from TAB in C mode
on my system. Can you give me some guidance on how to obtain the
"correct" behavior you mention?
It works correctly in the EMACS_22_BASE sources, but it is broken
in the trunk.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-24 21:55 ` Richard Stallman
@ 2007-12-24 22:33 ` martin rudalics
2007-12-26 5:29 ` Richard Stallman
0 siblings, 1 reply; 38+ messages in thread
From: martin rudalics @ 2007-12-24 22:33 UTC (permalink / raw)
To: rms; +Cc: miles, monnier, emacs-devel
> It works correctly in the EMACS_22_BASE sources, but it is broken
> in the trunk.
Because TAB is bound to `c-indent-command' in Emacs 22. But Miles was
complaining about the _behavior in the trunk_. FWIW, the following
change broke that:
2007-09-24 Dan Nicolaescu <dann@ics.uci.edu>
* progmodes/cc-mode.el (c-mode-base-map):
Use c-indent-line-or-region instead of c-indent-line.
I think that change should be reverted. We can always implement the
region-indenting behavior in `c-indent-command'.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-24 22:33 ` martin rudalics
@ 2007-12-26 5:29 ` Richard Stallman
2007-12-26 13:49 ` Vinicius Jose Latorre
2007-12-27 20:19 ` Juri Linkov
0 siblings, 2 replies; 38+ messages in thread
From: Richard Stallman @ 2007-12-26 5:29 UTC (permalink / raw)
To: martin rudalics; +Cc: miles, monnier, emacs-devel
I cleaned up the confusion in c-indent-line-or-region.
I also made `region-active-p' do the same thing it does in XEmacs.
The function to check whether a command should operate on the region
instead of whatever it normally does
is now called `use-region-p'.
I fixed several files whose behavior might have been affected
by the fact that `region-active-p' is now defined in Emacs.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-26 5:29 ` Richard Stallman
@ 2007-12-26 13:49 ` Vinicius Jose Latorre
2007-12-26 21:26 ` Richard Stallman
2007-12-27 20:19 ` Juri Linkov
1 sibling, 1 reply; 38+ messages in thread
From: Vinicius Jose Latorre @ 2007-12-26 13:49 UTC (permalink / raw)
To: rms; +Cc: martin rudalics, emacs-devel, monnier, miles
> I cleaned up the confusion in c-indent-line-or-region.
>
> I also made `region-active-p' do the same thing it does in XEmacs.
> The function to check whether a command should operate on the region
> instead of whatever it normally does
> is now called `use-region-p'.
>
> I fixed several files whose behavior might have been affected
> by the fact that `region-active-p' is now defined in Emacs.
>
ps-print is one of the files affected.
Does (mark) have the same meaning as (region-active-p) now?
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-26 5:29 ` Richard Stallman
2007-12-26 13:49 ` Vinicius Jose Latorre
@ 2007-12-27 20:19 ` Juri Linkov
2007-12-28 13:55 ` Richard Stallman
2007-12-28 13:55 ` Richard Stallman
1 sibling, 2 replies; 38+ messages in thread
From: Juri Linkov @ 2007-12-27 20:19 UTC (permalink / raw)
To: rms; +Cc: martin rudalics, emacs-devel, monnier, miles
> I also made `region-active-p' do the same thing it does in XEmacs.
What is the purpose of `region-active-p' in Emacs? Is it only for
compatibility with XEmacs? If so, then it seems it is not necessary
since compatibility code checks for (featurep 'xemacs) and as I see
now also for a new function (fboundp 'use-region-p).
> The function to check whether a command should operate on the region
> instead of whatever it normally does is now called `use-region-p'.
Perhaps a better function name could start with the `region-...' prefix
for consistency with other related functions.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-27 20:19 ` Juri Linkov
@ 2007-12-28 13:55 ` Richard Stallman
2007-12-28 13:55 ` Richard Stallman
1 sibling, 0 replies; 38+ messages in thread
From: Richard Stallman @ 2007-12-28 13:55 UTC (permalink / raw)
To: Juri Linkov; +Cc: rudalics, emacs-devel, monnier, miles
What is the purpose of `region-active-p' in Emacs? Is it only for
compatibility with XEmacs?
Yes, I think that will simplify some code
and avoid the need for conditionals in some places.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-27 20:19 ` Juri Linkov
2007-12-28 13:55 ` Richard Stallman
@ 2007-12-28 13:55 ` Richard Stallman
2008-01-03 21:52 ` Juri Linkov
1 sibling, 1 reply; 38+ messages in thread
From: Richard Stallman @ 2007-12-28 13:55 UTC (permalink / raw)
To: Juri Linkov; +Cc: rudalics, emacs-devel, monnier, miles
> The function to check whether a command should operate on the region
> instead of whatever it normally does is now called `use-region-p'.
Perhaps a better function name could start with the `region-...' prefix
for consistency with other related functions.
That parallelism is desirable, but it is not the only factor in
choosing a good name. The name `use-region-p' seems good to me, and I
don't see a better one.
Can you suggest another name that you think is better?
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-28 13:55 ` Richard Stallman
@ 2008-01-03 21:52 ` Juri Linkov
2008-01-03 23:50 ` Miles Bader
0 siblings, 1 reply; 38+ messages in thread
From: Juri Linkov @ 2008-01-03 21:52 UTC (permalink / raw)
To: rms; +Cc: rudalics, emacs-devel, monnier, miles
> > The function to check whether a command should operate on the region
> > instead of whatever it normally does is now called `use-region-p'.
>
> Perhaps a better function name could start with the `region-...' prefix
> for consistency with other related functions.
>
> That parallelism is desirable, but it is not the only factor in
> choosing a good name. The name `use-region-p' seems good to me, and I
> don't see a better one.
>
> Can you suggest another name that you think is better?
What about `region-use-p'? It starts with a prefix `region-' and its
suffix `use-p' is more meaningful than `region-p' in `use-region-p'.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2008-01-03 21:52 ` Juri Linkov
@ 2008-01-03 23:50 ` Miles Bader
0 siblings, 0 replies; 38+ messages in thread
From: Miles Bader @ 2008-01-03 23:50 UTC (permalink / raw)
To: Juri Linkov; +Cc: rudalics, rms, monnier, emacs-devel
Juri Linkov <juri@jurta.org> writes:
>> Can you suggest another name that you think is better?
>
> What about `region-use-p'? It starts with a prefix `region-' and its
> suffix `use-p' is more meaningful than `region-p' in `use-region-p'.
"use-p" doesn't make much sense...
There are multiple naming conventions used in Emacs: some people like
to rigidly use a "package prefix" style -- e.g. TYPE-FUNNAME -- whereas
a more traditional lisp convention is to instead prefer following
English conventions, which often are of the form "ACTION-TYPE" (for
actions) or "TYPE-PROPERTY" (for queries).
For instance, "make-FOO" is a traditional lisp name, whereas people
coming from other communities often will use something like "FOO-create"
instead to maintain the rigid prefix convention.
Richard's name fits traditional lisp style well.
-Miles
--
"Don't just question authority,
Don't forget to question me."
-- Jello Biafra
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-22 9:28 ` martin rudalics
2007-12-22 13:48 ` Miles Bader
2007-12-22 21:08 ` Richard Stallman
@ 2007-12-23 0:51 ` Stefan Monnier
2007-12-23 9:13 ` martin rudalics
2 siblings, 1 reply; 38+ messages in thread
From: Stefan Monnier @ 2007-12-23 0:51 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel, rms, Miles Bader
> FWIW all indent-line-functions with the exception of `lisp-indent-line'
> either don't have arguments or, like `c-indent-line', `f90-indent-line',
> and `(c)perl-indent-line' expect completely different arguments here.
> Hence a generic solution seems hardly practicable.
I don't see the relation: these modes do not use indent-for-tab-command
and bind TAB to something else instead (except for perl-mode, maybe,
but we can change this one).
Stefan
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-23 0:51 ` Stefan Monnier
@ 2007-12-23 9:13 ` martin rudalics
0 siblings, 0 replies; 38+ messages in thread
From: martin rudalics @ 2007-12-23 9:13 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Miles Bader, rms, emacs-devel
> I don't see the relation: these modes do not use indent-for-tab-command
> and bind TAB to something else instead (except for perl-mode, maybe,
> but we can change this one).
I didn't check them all. But Miles' patch should permit us to _not_
override the standard binding of TAB in c-mode :-) and I suppose a
similar solution can be found for most other modes too.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-21 19:49 ` Richard Stallman
2007-12-22 0:11 ` Miles Bader
@ 2007-12-26 3:00 ` Miles Bader
1 sibling, 0 replies; 38+ messages in thread
From: Miles Bader @ 2007-12-26 3:00 UTC (permalink / raw)
To: rms; +Cc: rudalics, Stefan Monnier, emacs-devel
Richard Stallman <rms@gnu.org> writes:
> This said, IMNSHO the feature we're talking about shouldn't be
> implement in lisp-mode and c-mode but directly generically in
> indent-for-tab-command.
>
> If that works, by all means do it.
I've committed the final version of the patch I previously posted here,
which should implement this behavior.
-Miles
--
=====
(^o^;
(()))
*This is the cute octopus virus, please copy it into your sig so it can spread.
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: C-u prefix behavior of TAB broken
2007-12-17 14:27 ` Miles Bader
2007-12-17 19:03 ` martin rudalics
@ 2007-12-18 2:24 ` Richard Stallman
1 sibling, 0 replies; 38+ messages in thread
From: Richard Stallman @ 2007-12-18 2:24 UTC (permalink / raw)
To: Miles Bader; +Cc: rudalics, emacs-devel
Anyway, that feature is now broken.
That is an important feature -- can someone please debug it
and ack?
^ permalink raw reply [flat|nested] 38+ messages in thread
end of thread, other threads:[~2008-02-25 2:56 UTC | newest]
Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-16 22:07 C-u prefix behavior of TAB broken Miles Bader
2007-12-17 12:48 ` martin rudalics
2007-12-17 14:27 ` Miles Bader
2007-12-17 19:03 ` martin rudalics
2007-12-21 0:20 ` Stefan Monnier
2007-12-21 19:49 ` Richard Stallman
2007-12-22 0:11 ` Miles Bader
2007-12-22 9:28 ` martin rudalics
2007-12-22 13:48 ` Miles Bader
2007-12-22 17:41 ` martin rudalics
2007-12-22 19:52 ` Miles Bader
2007-12-22 22:35 ` martin rudalics
2007-12-22 22:59 ` Miles Bader
2008-02-24 19:05 ` Juri Linkov
2008-02-24 19:26 ` Miles Bader
2008-02-24 19:40 ` Juri Linkov
2008-02-25 2:56 ` Miles Bader
2007-12-23 0:55 ` Stefan Monnier
2007-12-23 1:39 ` Miles Bader
2007-12-23 21:49 ` Stefan Monnier
2007-12-22 21:08 ` Richard Stallman
2007-12-22 22:08 ` martin rudalics
2007-12-23 21:11 ` Richard Stallman
2007-12-23 21:44 ` martin rudalics
2007-12-24 21:55 ` Richard Stallman
2007-12-24 22:33 ` martin rudalics
2007-12-26 5:29 ` Richard Stallman
2007-12-26 13:49 ` Vinicius Jose Latorre
2007-12-26 21:26 ` Richard Stallman
2007-12-27 20:19 ` Juri Linkov
2007-12-28 13:55 ` Richard Stallman
2007-12-28 13:55 ` Richard Stallman
2008-01-03 21:52 ` Juri Linkov
2008-01-03 23:50 ` Miles Bader
2007-12-23 0:51 ` Stefan Monnier
2007-12-23 9:13 ` martin rudalics
2007-12-26 3:00 ` Miles Bader
2007-12-18 2:24 ` Richard Stallman
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).