* keep|flush-lines, how-many to be used backward.
@ 2007-09-24 16:08 Michaël Cadilhac
2007-09-24 17:27 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 19+ messages in thread
From: Michaël Cadilhac @ 2007-09-24 16:08 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1.1.1: Type: text/plain, Size: 299 bytes --]
I've been using this for a few days, and I find it quite useful. It may
be good to install.
The effect: C-u M-x how-many RET is how-many'ing in the text *before*
point. Same for C-u M-x keep-lines.
If this is not the right thing to do for such a feature, just say it,
I'll not insist too much.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: replace.patch --]
[-- Type: text/x-patch, Size: 4526 bytes --]
--- replace.el 26 Jul 2007 07:26:32 +0200 1.259
+++ replace.el 24 Sep 2007 18:04:34 +0200
@@ -525,10 +525,15 @@
(defun keep-lines-read-args (prompt)
"Read arguments for `keep-lines' and friends.
-Prompt for a regexp with PROMPT.
+Prompt for a regexp with PROMPT followed by some information and a colon.
Value is a list, (REGEXP)."
- (list (read-from-minibuffer prompt nil nil nil
- 'regexp-history nil t)
+ (list (read-from-minibuffer (concat prompt
+ (if (and transient-mark-mode mark-active)
+ " in the region: "
+ (if current-prefix-arg
+ " backward: "
+ ": ")))
+ nil nil nil 'regexp-history nil t)
nil nil t))
(defun keep-lines (regexp &optional rstart rend interactive)
@@ -547,7 +552,8 @@
Interactively, in Transient Mark mode when the mark is active, operate
on all lines whose accessible part is entirely contained in the region.
-Otherwise, the command applies to all lines starting after point.
+Otherwise, the command applies to all lines starting after point (or before
+point if a prefix argument is provided).
When calling this function from Lisp, you can pretend that it was
called interactively by passing a non-nil INTERACTIVE argument.
@@ -558,7 +564,7 @@
(interactive
(progn
(barf-if-buffer-read-only)
- (keep-lines-read-args "Keep lines (containing match for regexp): ")))
+ (keep-lines-read-args "Keep lines (containing match for regexp)")))
(if rstart
(progn
(goto-char (min rstart rend))
@@ -576,8 +582,8 @@
(unless (or (bolp) (eobp))
(forward-line 0))
(point-marker)))
- (setq rstart (point)
- rend (point-max-marker)))
+ (setq rstart (if current-prefix-arg (point-min) (point))
+ rend (if current-prefix-arg (point-marker) (point-max-marker))))
(goto-char rstart))
(save-excursion
(or (bolp) (forward-line 1))
@@ -620,9 +626,10 @@
Interactively, in Transient Mark mode when the mark is active, operate
on the contents of the region. Otherwise, operate from point to the
-end of (the accessible portion of) the buffer. When calling this function
-from Lisp, you can pretend that it was called interactively by passing
-a non-nil INTERACTIVE argument.
+end of (the accessible portion of) the buffer (or its beginning if a prefix
+argument is provided).
+When calling this function from Lisp, you can pretend that it was called
+interactively by passing a non-nil INTERACTIVE argument.
If a match is split across lines, all the lines it lies in are deleted.
They are deleted _before_ looking for the next match. Hence, a match
@@ -631,7 +638,7 @@
(interactive
(progn
(barf-if-buffer-read-only)
- (keep-lines-read-args "Flush lines (containing match for regexp): ")))
+ (keep-lines-read-args "Flush lines (containing match for regexp)")))
(if rstart
(progn
(goto-char (min rstart rend))
@@ -639,8 +646,8 @@
(if (and interactive transient-mark-mode mark-active)
(setq rstart (region-beginning)
rend (copy-marker (region-end)))
- (setq rstart (point)
- rend (point-max-marker)))
+ (setq rstart (if current-prefix-arg (point-min) (point))
+ rend (if current-prefix-arg (point-marker) (point-max-marker))))
(goto-char rstart))
(let ((case-fold-search (and case-fold-search
(isearch-no-upper-case-p regexp t))))
@@ -668,14 +675,16 @@
Interactively, in Transient Mark mode when the mark is active, operate
on the contents of the region. Otherwise, operate from point to the
-end of (the accessible portion of) the buffer.
+end of (the accessible portion of) the buffer (or its beginning if a
+prefix argument is provided).
This function starts looking for the next match from the end of
the previous match. Hence, it ignores matches that overlap
a previously found match."
(interactive
- (keep-lines-read-args "How many matches for (regexp): "))
+ (keep-lines-read-args "How many matches for (regexp)"))
+
(save-excursion
(if rstart
(progn
@@ -684,8 +693,8 @@
(if (and interactive transient-mark-mode mark-active)
(setq rstart (region-beginning)
rend (region-end))
- (setq rstart (point)
- rend (point-max)))
+ (setq rstart (if current-prefix-arg (point-min) (point))
+ rend (if current-prefix-arg (point) (point-max))))
(goto-char rstart))
(let ((count 0)
opoint
[-- Attachment #1.1.3: Type: text/plain, Size: 329 bytes --]
--
| Michaël `Micha' Cadilhac | In a World without Walls and Fences, |
| http://michael.cadilhac.name | who needs Windows and Gates? |
| JID/MSN: | -- Dino Esposito |
`---- michael.cadilhac@gmail.com | - --'
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 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] 19+ messages in thread
* RE: keep|flush-lines, how-many to be used backward.
2007-09-24 16:08 keep|flush-lines, how-many to be used backward Michaël Cadilhac
@ 2007-09-24 17:27 ` Drew Adams
2007-09-24 17:42 ` Michaël Cadilhac
2007-09-25 10:44 ` Richard Stallman
2007-09-25 20:39 ` Michaël Cadilhac
2 siblings, 1 reply; 19+ messages in thread
From: Drew Adams @ 2007-09-24 17:27 UTC (permalink / raw)
To: "Michaël" Cadilhac, emacs-devel
> I've been using this for a few days, and I find it quite useful.
> It may be good to install. The effect: C-u M-x how-many RET is
> how-many'ing in the text *before* point. Same for C-u M-x keep-lines.
Dunno. Why do you find that very useful? It's only one more keystroke to do
without it: `C-SPC M-<' instead of `C-u'. (Admittedly, that's a complex
keystroke, involving Shift on many keyboards.)
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-24 17:27 ` Drew Adams
@ 2007-09-24 17:42 ` Michaël Cadilhac
2007-09-25 14:10 ` Stefan Monnier
0 siblings, 1 reply; 19+ messages in thread
From: Michaël Cadilhac @ 2007-09-24 17:42 UTC (permalink / raw)
To: Drew Adams; +Cc: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 1098 bytes --]
"Drew Adams" <drew.adams@oracle.com> writes:
>> I've been using this for a few days, and I find it quite useful.
>> It may be good to install. The effect: C-u M-x how-many RET is
>> how-many'ing in the text *before* point. Same for C-u M-x keep-lines.
>
> Dunno. Why do you find that very useful? It's only one more keystroke to do
> without it: `C-SPC M-<' instead of `C-u'. (Admittedly, that's a complex
> keystroke, involving Shift on many keyboards.)
Well, I don't have this Transient-mark-mode thingy enabled. So I must
type C-SPC C-SPC M-< then C-x C-x to return to the point (I mostly use
`how-many'), then C-g to remove this BSOD-like Transient mark. For me,
its
C-SPC C-SPC M-< [...] C-x C-x C-g versus C-u [...]
That simple :-)
--
| Michaël `Micha' Cadilhac | Je veut dire que la loi francaise |
| http://michael.cadilhac.name | est overwritable par le |
| JID/MSN: | reglement interieur il me semble. |
`---- michael.cadilhac@gmail.com | -- ElBarto - --'
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 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] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-24 16:08 keep|flush-lines, how-many to be used backward Michaël Cadilhac
2007-09-24 17:27 ` Drew Adams
@ 2007-09-25 10:44 ` Richard Stallman
2007-09-25 20:39 ` Michaël Cadilhac
2 siblings, 0 replies; 19+ messages in thread
From: Richard Stallman @ 2007-09-25 10:44 UTC (permalink / raw)
To: Michaël Cadilhac; +Cc: emacs-devel
The effect: C-u M-x how-many RET is how-many'ing in the text *before*
point. Same for C-u M-x keep-lines.
I am not against it, since it is simple.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-24 17:42 ` Michaël Cadilhac
@ 2007-09-25 14:10 ` Stefan Monnier
2007-09-25 14:36 ` Michaël Cadilhac
0 siblings, 1 reply; 19+ messages in thread
From: Stefan Monnier @ 2007-09-25 14:10 UTC (permalink / raw)
To: Michaël Cadilhac; +Cc: Drew Adams, emacs-devel
>>> I've been using this for a few days, and I find it quite useful.
>>> It may be good to install. The effect: C-u M-x how-many RET is
>>> how-many'ing in the text *before* point. Same for C-u M-x keep-lines.
>>
>> Dunno. Why do you find that very useful? It's only one more keystroke to do
>> without it: `C-SPC M-<' instead of `C-u'. (Admittedly, that's a complex
>> keystroke, involving Shift on many keyboards.)
> Well, I don't have this Transient-mark-mode thingy enabled. So I must
> type C-SPC C-SPC M-< then C-x C-x to return to the point (I mostly use
> `how-many'), then C-g to remove this BSOD-like Transient mark. For me,
> its
Hmm... you shouldn't need C-g here, sounds like a bug.
Stefan
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-25 14:10 ` Stefan Monnier
@ 2007-09-25 14:36 ` Michaël Cadilhac
2007-09-26 5:01 ` Stefan Monnier
0 siblings, 1 reply; 19+ messages in thread
From: Michaël Cadilhac @ 2007-09-25 14:36 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Drew Adams, emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 1354 bytes --]
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>>> I've been using this for a few days, and I find it quite useful.
>>>> It may be good to install. The effect: C-u M-x how-many RET is
>>>> how-many'ing in the text *before* point. Same for C-u M-x keep-lines.
>>>
>>> Dunno. Why do you find that very useful? It's only one more keystroke to do
>>> without it: `C-SPC M-<' instead of `C-u'. (Admittedly, that's a complex
>>> keystroke, involving Shift on many keyboards.)
>
>> Well, I don't have this Transient-mark-mode thingy enabled. So I must
>> type C-SPC C-SPC M-< then C-x C-x to return to the point (I mostly use
>> `how-many'), then C-g to remove this BSOD-like Transient mark. For me,
>> its
>
> Hmm... you shouldn't need C-g here, sounds like a bug.
Are you sure? I thought is was a feature. Like, I need to mark
(transiently) 10 lines before point, so I do C-SPC C-SPC C-u 10 C-p,
then I see that I started the region two chars before where I wanted, so
I do C-x C-x and 2 C-f. Nop?
--
| Michaël `Micha' Cadilhac | - Dear God |
| http://michael.cadilhac.name | - Yes, My child ? |
| JID/MSN: | - I would like to file a bug report. |
`---- michael.cadilhac@gmail.com | -- XKCD - --'
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 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] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-24 16:08 keep|flush-lines, how-many to be used backward Michaël Cadilhac
2007-09-24 17:27 ` Drew Adams
2007-09-25 10:44 ` Richard Stallman
@ 2007-09-25 20:39 ` Michaël Cadilhac
2007-09-25 20:56 ` Juri Linkov
2 siblings, 1 reply; 19+ messages in thread
From: Michaël Cadilhac @ 2007-09-25 20:39 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 786 bytes --]
michael@cadilhac.name (Michaël Cadilhac) writes:
> I've been using this for a few days, and I find it quite useful. It may
> be good to install.
>
> The effect: C-u M-x how-many RET is how-many'ing in the text *before*
> point. Same for C-u M-x keep-lines.
>
> If this is not the right thing to do for such a feature, just say it,
> I'll not insist too much.
Since one (1) person was « not against it », I'll probably install that
on Friday.
--
| Michaël `Micha' Cadilhac | Jesus saves, |
| http://michael.cadilhac.name | but only Buddha |
| JID/MSN: | makes incremental backups. |
`---- michael.cadilhac@gmail.com | - --'
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 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] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-25 20:39 ` Michaël Cadilhac
@ 2007-09-25 20:56 ` Juri Linkov
2007-09-25 21:01 ` Michaël Cadilhac
0 siblings, 1 reply; 19+ messages in thread
From: Juri Linkov @ 2007-09-25 20:56 UTC (permalink / raw)
To: Michaël Cadilhac; +Cc: emacs-devel
>> I've been using this for a few days, and I find it quite useful. It may
>> be good to install.
>>
>> The effect: C-u M-x how-many RET is how-many'ing in the text *before*
>> point. Same for C-u M-x keep-lines.
>>
>> If this is not the right thing to do for such a feature, just say it,
>> I'll not insist too much.
>
> Since one (1) person was « not against it », I'll probably install that
> on Friday.
What do you think about using a negative argument to operate before point?
Many Emacs commands change their direction when the argument is negative,
e.g. for `kill-sexp' the negative arg means kill sexps before point, etc.
keep|flush-lines, how-many could do the same, e.g. `M-- M-x keep-lines'.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-25 20:56 ` Juri Linkov
@ 2007-09-25 21:01 ` Michaël Cadilhac
2007-09-25 21:49 ` Juri Linkov
0 siblings, 1 reply; 19+ messages in thread
From: Michaël Cadilhac @ 2007-09-25 21:01 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 1232 bytes --]
Juri Linkov <juri@jurta.org> writes:
> What do you think about using a negative argument to operate before point?
> Many Emacs commands change their direction when the argument is negative,
> e.g. for `kill-sexp' the negative arg means kill sexps before point, etc.
Well, on the one hand, I understand what 18 kill-sexp does. It kills 18
sexps, and this is fine if you want to kill that much sexps. On the
other hand, what does 18 how-many means?
You're asking for a differentiation between a positive and a negative
argument, but what is the *purpose* of the value of this argument?
My proposal uses the prefix argument as a flag, not as an integer value.
> keep|flush-lines, how-many could do the same, e.g. `M-- M-x keep-lines'.
M-- puts a prefix of -1, so M-- M-x keep-lines would be the same as M-u
M-x keep-lines.
I hope I don't have misunderstood what you proposed.
--
| Michaël `Micha' Cadilhac | Libertude, |
| http://michael.cadilhac.name | Égalitude, |
| JID/MSN: | Fraternitude. |
`---- michael.cadilhac@gmail.com | -- À peu près S.R. - --'
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 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] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-25 21:01 ` Michaël Cadilhac
@ 2007-09-25 21:49 ` Juri Linkov
2007-09-28 9:32 ` Michaël Cadilhac
0 siblings, 1 reply; 19+ messages in thread
From: Juri Linkov @ 2007-09-25 21:49 UTC (permalink / raw)
To: Michaël Cadilhac; +Cc: emacs-devel
>> What do you think about using a negative argument to operate before point?
>> Many Emacs commands change their direction when the argument is negative,
>> e.g. for `kill-sexp' the negative arg means kill sexps before point, etc.
>
> Well, on the one hand, I understand what 18 kill-sexp does. It kills 18
> sexps, and this is fine if you want to kill that much sexps. On the
> other hand, what does 18 how-many means?
>
> You're asking for a differentiation between a positive and a negative
> argument, but what is the *purpose* of the value of this argument?
My purpose was to propose to reserve C-u for other possible future uses.
For example, the argument of `C-u C-s' turns string isearch into
regexp isearch. Since keep-lines and co works with regexps by default,
C-u could be used to read and search the string.
Another example is query-replace from the same file replace.el.
`C-u M-%' replaces delimited matches surrounded by word boundaries,
but I think this is less useful for keep-lines than using C-u to
search strings instead of regexps.
Using C-u now to change the direction will prevent these commands from
extending to do more useful things in future.
OTOH, there is a good tradition to use the negative argument to change the
direction in which the command operates. Since this requires the argument
to be numeric, we could find a way to interpret this number usefully.
For example, this number could count lines or paragraphs to operate on.
But this could be implemented later when someone comes with a good idea
of using the number. For now, -1 (`M--') could mean operating in the
opposite direction. This argument will have a good mnemonics.
>> keep|flush-lines, how-many could do the same, e.g. `M-- M-x keep-lines'.
>
> M-- puts a prefix of -1, so M-- M-x keep-lines would be the same as M-u
> M-x keep-lines.
`M-- M-x keep-lines' is the same as `C-u - M-x keep-lines'
(see `prefix-numeric-value').
Please also note that usually the command should have parameters it reads
in its function arguments. So it's better to change
(defun keep-lines (regexp &optional rstart rend interactive)
to
(defun keep-lines (regexp &optional rstart rend interactive direction)
or better to more general:
(defun keep-lines (regexp &optional rstart rend interactive arg)
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-25 14:36 ` Michaël Cadilhac
@ 2007-09-26 5:01 ` Stefan Monnier
0 siblings, 0 replies; 19+ messages in thread
From: Stefan Monnier @ 2007-09-26 5:01 UTC (permalink / raw)
To: Michaël Cadilhac; +Cc: Drew Adams, emacs-devel
>>>>> I've been using this for a few days, and I find it quite useful.
>>>>> It may be good to install. The effect: C-u M-x how-many RET is
>>>>> how-many'ing in the text *before* point. Same for C-u M-x keep-lines.
>>>>
>>>> Dunno. Why do you find that very useful? It's only one more keystroke to do
>>>> without it: `C-SPC M-<' instead of `C-u'. (Admittedly, that's a complex
>>>> keystroke, involving Shift on many keyboards.)
>>
>>> Well, I don't have this Transient-mark-mode thingy enabled. So I must
>>> type C-SPC C-SPC M-< then C-x C-x to return to the point (I mostly use
>>> `how-many'), then C-g to remove this BSOD-like Transient mark. For me,
>>> its
>>
>> Hmm... you shouldn't need C-g here, sounds like a bug.
> Are you sure? I thought is was a feature. Like, I need to mark
> (transiently) 10 lines before point, so I do C-SPC C-SPC C-u 10 C-p,
> then I see that I started the region two chars before where I wanted, so
> I do C-x C-x and 2 C-f. Nop?
I don't understand what you're trying to say.
I only wanted to say that C-g shouldn't be needed if you use C-SPC C-SPC to
activate the temporary transient-mark-mode and then use M-x how-many (the
`how-many' should "consume" the transient mark).
Stefan
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-25 21:49 ` Juri Linkov
@ 2007-09-28 9:32 ` Michaël Cadilhac
2007-09-28 10:52 ` Robert J. Chassell
` (3 more replies)
0 siblings, 4 replies; 19+ messages in thread
From: Michaël Cadilhac @ 2007-09-28 9:32 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 3150 bytes --]
Juri Linkov <juri@jurta.org> writes:
>>> What do you think about using a negative argument to operate before point?
>>> Many Emacs commands change their direction when the argument is negative,
>>> e.g. for `kill-sexp' the negative arg means kill sexps before point, etc.
>>
>> Well, on the one hand, I understand what 18 kill-sexp does. It kills 18
>> sexps, and this is fine if you want to kill that much sexps. On the
>> other hand, what does 18 how-many means?
>>
>> You're asking for a differentiation between a positive and a negative
>> argument, but what is the *purpose* of the value of this argument?
>
> My purpose was to propose to reserve C-u for other possible future uses.
I fully understand that a prefix argument changes the behavior of a
function ; I fully understand that a numeric prefix argument repeats the
action that much time, or by modifying N times its behavior.
What I fail to agree with, is that a prefix argument can be a
three-state boolean : present, negative or positive. I think it's just
a hack, and should not be used like that. A user that sees that C-u and
C-- has different behavior will try to figure out what C-9 will do, but
it'd be nonsense. Don't you agree?
> Using C-u now to change the direction will prevent these commands from
> extending to do more useful things in future.
If I continue in your way, I think you are suggesting that we don't use
the prefix value 2 in M-x search because it can be used for future
features. It's a little bit extreme, but wanting to differentiate = 0, < 0
and > 0 will eventually lead to this.
To sum up, I think the prefix argument has only two use cases :
- As a boolean (present/absent),
- As a number.
Wanting to mix those two is, to me, a hack.
If we're going to camp on our positions :-) does someone else have an
opinion ?
>>> keep|flush-lines, how-many could do the same, e.g. `M-- M-x keep-lines'.
>>
>> M-- puts a prefix of -1, so M-- M-x keep-lines would be the same as M-u
>> M-x keep-lines.
>
> `M-- M-x keep-lines' is the same as `C-u - M-x keep-lines'
> (see `prefix-numeric-value').
I was saying that, with the first proposal, C-- would have the same
behavior than C-u.
> Please also note that usually the command should have parameters it reads
> in its function arguments. So it's better to change
> (defun keep-lines (regexp &optional rstart rend interactive direction)
Well, this is another matter. I want to do the following with those
three functions :
- Remove the `interactive' flag (it's silly),
- Remove the `optional'.
That way, `direction' is not needed, as the caller should provide rstart
and rend (like in nearly all the functions that take a region -- as a
first count, 90%). The direction is just an interactive help.
--
| Michaël `Micha' Cadilhac | The second-degree, |
| http://michael.cadilhac.name | is kind of |
| JID/MSN: | the semantic back slang. |
`---- michael.cadilhac@gmail.com | - --'
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 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] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-28 9:32 ` Michaël Cadilhac
@ 2007-09-28 10:52 ` Robert J. Chassell
2007-09-28 10:59 ` Michaël Cadilhac
2007-09-29 16:10 ` Richard Stallman
2007-09-28 15:50 ` Drew Adams
` (2 subsequent siblings)
3 siblings, 2 replies; 19+ messages in thread
From: Robert J. Chassell @ 2007-09-28 10:52 UTC (permalink / raw)
To: emacs-devel
What I fail to agree with, is that a prefix argument can be a
three-state boolean=A0: present, negative or positive.
It is straight forward to provide three options or two depending on
whether the code distinguishes between a list and an integer.
(You can also distinguish between the integer -1 and the symbol `-',
but I never have.)
See:
(info "(elisp)Prefix Command Arguments")
which says,
Here are the possible values of a raw prefix argument:
* `nil', meaning there is no prefix argument. Its numeric value is
1, but numerous commands make a distinction between `nil' and the
integer 1.
* An integer, which stands for itself.
* A list of one element, which is an integer. This form of prefix
argument results from one or a succession of `C-u''s with no
digits. The numeric value is the integer in the list, but some
commands make a distinction between such a list and an integer
alone.
* The symbol `-'. This indicates that `M--' or `C-u -' was typed,
without following digits. The equivalent numeric value is -1, but
some commands make a distinction between the integer -1 and the
symbol `-'.
That Info shows the results of interactively invoking a defun called
`display-prefix' in nine different ways. (The whole defun is shown,
so you can copy it.)
With a slightly different definition for display-prefix than provided
by the manual,
(defun display-prefix (arg)
"Display the value of the raw prefix arg."
(interactive "P")
(if (listp arg)
(message "%s: is a list" arg)
(message "%s: is not a list" arg)))
we find:
list present
M-x display-prefix -| nil: is a list
C-u M-x display-prefix -| (4): is a list
C-u C-u M-x display-prefix -| (16): is a list
no list; number positive.
C-u 4 M-x display-prefix -| 4: is not a list
M-4 M-x display-prefix -| 4: is not a list ; (Same as `C-u 4'.)
no list; number negative or non-existant
C-u - M-x display-prefix -| -: is not a list
M-- M-x display-prefix -| -: is not a list ; (Same as `C-u -'.)
C-u - 7 M-x display-prefix -| -7: is not a list
M-- 7 M-x display-prefix -| -7: is not a list ; (Same as `C-u -7'.)
--
Robert J. Chassell GnuPG Key ID: 004B4AC8
bob@rattlesnake.com bob@gnu.org
http://www.rattlesnake.com http://www.teak.cc
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-28 10:52 ` Robert J. Chassell
@ 2007-09-28 10:59 ` Michaël Cadilhac
2007-09-29 16:10 ` Richard Stallman
1 sibling, 0 replies; 19+ messages in thread
From: Michaël Cadilhac @ 2007-09-28 10:59 UTC (permalink / raw)
To: bob; +Cc: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 758 bytes --]
"Robert J. Chassell" <bob@rattlesnake.com> writes:
> What I fail to agree with, is that a prefix argument can be a
> three-state boolean=A0: present, negative or positive.
>
> It is straight forward to provide three options or two depending on
> whether the code distinguishes between a list and an integer.
Okey, I wasn't clear. My point is that a three-state boolean is a hack,
not that it's not feasible.
--
| Michaël `Micha' Cadilhac | All your base are belong to us. |
| http://michael.cadilhac.name | You have no chance to survive |
| JID/MSN: | make your time, hahaha. |
`---- michael.cadilhac@gmail.com | -- Zero Wings - --'
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 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] 19+ messages in thread
* RE: keep|flush-lines, how-many to be used backward.
2007-09-28 9:32 ` Michaël Cadilhac
2007-09-28 10:52 ` Robert J. Chassell
@ 2007-09-28 15:50 ` Drew Adams
2007-09-28 22:25 ` Robert J. Chassell
2007-09-29 22:48 ` Juri Linkov
3 siblings, 0 replies; 19+ messages in thread
From: Drew Adams @ 2007-09-28 15:50 UTC (permalink / raw)
To: "Michaël" Cadilhac, Juri Linkov; +Cc: emacs-devel
> To sum up, I think the prefix argument has only two use cases :
> - As a boolean (present/absent),
> - As a number.
>
> Wanting to mix those two is, to me, a hack.
>
> If we're going to camp on our positions :-) does someone else have an
> opinion ?
Yes (since you asked), FWIW, and without reference to the specific
prefix-arg use in this thread -
A raw prefix arg can have different kinds of values (nil, consp, integer
(negative, zero, positive)), and the numeric values of these different raw
values can also be used. Functions should be free to use any of these values
(both raw and numeric) as they like. There should be no limits or
conventions that restrict this.
However, functions that interpret a prefix arg owe it to their users to
clearly explain the behavior of the prefix arg in the doc string. As long as
that is done, I see no problem.
However #2: Other things being equal, there are some common use patterns
that can be followed (can be, not need to be), and that can make life easier
for users:
* positive numeric arg N means repeat N times
* -N means reverse the "direction" of N, whatever "direction" might mean in
a particular context.
* the default behavior (without any explicit prefix arg) should be the
behavior that users will use most
In sum:
1. No strict convention or standard meaning that limits what you do with a
function you define.
2. If there is no reason not to, you might want to follow some common use
patterns, interpreting them as appropriate in your context.
3. Document all prefix-arg behavior clearly in the doc string.
A prefix arg is a useful way to multiply the functionality of a single
function, typically a command that is bound to a key. Programmers should not
feel limited in any way in the use they make of prefix args. Explore,
experiment, do what you want with it; it's just a tool. If you want to make
things easier on users, however, and if there is no reason not to, then you
might want to follow some informal conventions - it's up to you.
Just my opinion, of course.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-28 9:32 ` Michaël Cadilhac
2007-09-28 10:52 ` Robert J. Chassell
2007-09-28 15:50 ` Drew Adams
@ 2007-09-28 22:25 ` Robert J. Chassell
2007-09-29 22:48 ` Juri Linkov
3 siblings, 0 replies; 19+ messages in thread
From: Robert J. Chassell @ 2007-09-28 22:25 UTC (permalink / raw)
To: emacs-devel
What I fail to agree with, is that a prefix argument can be a
three-state boolean=A0: present, negative or positive.
It is straight forward to provide three options or two depending on
whether the code distinguishes between a list and an integer.
(You can also distinguish between the integer -1 and the symbol `-',
but I never have.)
See:
(info "(elisp)Prefix Command Arguments")
which says,
Here are the possible values of a raw prefix argument:
* `nil', meaning there is no prefix argument. Its numeric value is
1, but numerous commands make a distinction between `nil' and the
integer 1.
* An integer, which stands for itself.
* A list of one element, which is an integer. This form of prefix
argument results from one or a succession of `C-u''s with no
digits. The numeric value is the integer in the list, but some
commands make a distinction between such a list and an integer
alone.
* The symbol `-'. This indicates that `M--' or `C-u -' was typed,
without following digits. The equivalent numeric value is -1, but
some commands make a distinction between the integer -1 and the
symbol `-'.
That Info shows the results of interactively invoking a defun called
`display-prefix' in nine different ways. (The whole defun is shown,
so you can copy it.)
With a slightly different definition for display-prefix than provided
by the manual,
(defun display-prefix (arg)
"Display the value of the raw prefix arg."
(interactive "P")
(if (listp arg)
(message "%s: is a list" arg)
(message "%s: is not a list" arg)))
we find:
list present
M-x display-prefix -| nil: is a list
C-u M-x display-prefix -| (4): is a list
C-u C-u M-x display-prefix -| (16): is a list
no list; number positive.
C-u 4 M-x display-prefix -| 4: is not a list
M-4 M-x display-prefix -| 4: is not a list ; (Same as `C-u 4'.)
no list; number negative or non-existant
C-u - M-x display-prefix -| -: is not a list
M-- M-x display-prefix -| -: is not a list ; (Same as `C-u -'.)
C-u - 7 M-x display-prefix -| -7: is not a list
M-- 7 M-x display-prefix -| -7: is not a list ; (Same as `C-u -7'.)
--
Robert J. Chassell GnuPG Key ID: 004B4AC8
bob@rattlesnake.com bob@gnu.org
http://www.rattlesnake.com http://www.teak.cc
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-28 10:52 ` Robert J. Chassell
2007-09-28 10:59 ` Michaël Cadilhac
@ 2007-09-29 16:10 ` Richard Stallman
1 sibling, 0 replies; 19+ messages in thread
From: Richard Stallman @ 2007-09-29 16:10 UTC (permalink / raw)
To: bob; +Cc: emacs-devel
What I fail to agree with, is that a prefix argument can be a
three-state boolean=A0: present, negative or positive.
It is straight forward to provide three options or two depending on
whether the code distinguishes between a list and an integer.
I don't really like the idea of that much complexity.
If you want anything unusual you can set up a region.
It doesn't happen often enough to be worth saving a few characters in.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: keep|flush-lines, how-many to be used backward.
2007-09-28 9:32 ` Michaël Cadilhac
` (2 preceding siblings ...)
2007-09-28 22:25 ` Robert J. Chassell
@ 2007-09-29 22:48 ` Juri Linkov
2007-09-30 2:18 ` Drew Adams
3 siblings, 1 reply; 19+ messages in thread
From: Juri Linkov @ 2007-09-29 22:48 UTC (permalink / raw)
To: Michaël Cadilhac; +Cc: emacs-devel
> What I fail to agree with, is that a prefix argument can be a
> three-state boolean: present, negative or positive. I think it's just
> a hack, and should not be used like that. A user that sees that C-u and
> C-- has different behavior will try to figure out what C-9 will do, but
> it'd be nonsense. Don't you agree?
I think until the meaning of the positive numeric argument is implemented,
it should do nothing special, i.e. do not change the default behavior.
>> Using C-u now to change the direction will prevent these commands from
>> extending to do more useful things in future.
>
> If I continue in your way, I think you are suggesting that we don't use
> the prefix value 2 in M-x search because it can be used for future
> features. It's a little bit extreme, but wanting to differentiate = 0, < 0
> and > 0 will eventually lead to this.
If you mean the prefix value 2 of a search command, it makes sense to use
it as a number N to find the N-th occurrence of the search string starting
from the current position.
> To sum up, I think the prefix argument has only two use cases:
> - As a boolean (present/absent),
> - As a number.
>
> Wanting to mix those two is, to me, a hack.
The last case can be subdivided into a positive, negative number and zero.
M-0 often is a special case (like e.g. in `M-0 w' in dired to copy the
absolute file name). For keep-lines, flush-lines M-0 could be interpreted
as operating on the whole buffer. I miss this functionality very much.
I always want for these commands to operate on the whole buffer no matter
where point is located before calling these commands, but I need every
time to put point to the beginning of the buffer. With a special argument
to operate on the whole buffer these commands will be easier to use.
>> Please also note that usually the command should have parameters it reads
>> in its function arguments. So it's better to change
>
>> (defun keep-lines (regexp &optional rstart rend interactive direction)
>
> Well, this is another matter. I want to do the following with those
> three functions:
> - Remove the `interactive' flag (it's silly),
> - Remove the `optional'.
>
> That way, `direction' is not needed, as the caller should provide rstart
> and rend (like in nearly all the functions that take a region -- as a
> first count, 90%). The direction is just an interactive help.
It's a good idea to remove the `interactive' flag. If Richard will agree
to your change, please replace it.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 19+ messages in thread
* RE: keep|flush-lines, how-many to be used backward.
2007-09-29 22:48 ` Juri Linkov
@ 2007-09-30 2:18 ` Drew Adams
0 siblings, 0 replies; 19+ messages in thread
From: Drew Adams @ 2007-09-30 2:18 UTC (permalink / raw)
To: Juri Linkov, "Michael" Cadilhac; +Cc: emacs-devel
> For keep-lines, flush-lines M-0 could be interpreted
> as operating on the whole buffer. I miss this functionality very much.
> I always want for these commands to operate on the whole buffer no matter
> where point is located before calling these commands, but I need every
> time to put point to the beginning of the buffer. With a special argument
> to operate on the whole buffer these commands will be easier to use.
I raised precisely that point, but with a different solution - see thread
"Why act from point forward by default, instead of whole buffer?" My
proposal was to act on the whole buffer unless the region is active.
Richard answered the question Why? about the status quo (which was really
meant as Why not change?) with "historical behavior" and said he didn't want
to change it. Perhaps he will go along with your M-0 proposal. I'd rather be
able to act on the buffer without any prefix arg, but M-0 is better than
nothing - good idea.
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2007-09-30 2:18 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-24 16:08 keep|flush-lines, how-many to be used backward Michaël Cadilhac
2007-09-24 17:27 ` Drew Adams
2007-09-24 17:42 ` Michaël Cadilhac
2007-09-25 14:10 ` Stefan Monnier
2007-09-25 14:36 ` Michaël Cadilhac
2007-09-26 5:01 ` Stefan Monnier
2007-09-25 10:44 ` Richard Stallman
2007-09-25 20:39 ` Michaël Cadilhac
2007-09-25 20:56 ` Juri Linkov
2007-09-25 21:01 ` Michaël Cadilhac
2007-09-25 21:49 ` Juri Linkov
2007-09-28 9:32 ` Michaël Cadilhac
2007-09-28 10:52 ` Robert J. Chassell
2007-09-28 10:59 ` Michaël Cadilhac
2007-09-29 16:10 ` Richard Stallman
2007-09-28 15:50 ` Drew Adams
2007-09-28 22:25 ` Robert J. Chassell
2007-09-29 22:48 ` Juri Linkov
2007-09-30 2:18 ` Drew Adams
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).