* Re: Longlines and insert
2005-11-15 20:41 ` Paul Pogonyshev
@ 2005-11-15 22:22 ` Kevin Rodgers
2005-11-15 22:24 ` Kim F. Storm
` (2 subsequent siblings)
3 siblings, 0 replies; 20+ messages in thread
From: Kevin Rodgers @ 2005-11-15 22:22 UTC (permalink / raw)
Paul Pogonyshev wrote:
> I think (and as far as I understood, Chong Yidong does too) that this is
> a welcoming message for future problems. You patch up a piece of code,
> while there are hundreds other lisp files, many of which insert newlines,
> some of which need to be hard. We probably need something generic. At
> the very least we need a convenience function to create a newline-string
> with the necessary properties already set, so we don't have to go over
> the lines above each time.
CY has identified a single Lisp file (sendmail.el) that needs to be
fixed, and we can guess that other message composition libraries do as
well.
Right now the most generic solution is the one he suggested:
(let ((use-hard-newlines t)) (newline))
But I agree with you that a convenience function for strings would be
better. A good start would be to add an &optional OBJECT argument for
set-hard-newline-properties that gets passed to put-text-property.
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-15 20:41 ` Paul Pogonyshev
2005-11-15 22:22 ` Kevin Rodgers
@ 2005-11-15 22:24 ` Kim F. Storm
2005-11-16 3:05 ` Chong Yidong
2005-11-16 10:48 ` Richard M. Stallman
2005-11-15 23:09 ` Stefan Monnier
2005-11-15 23:33 ` Ryan Yeske
3 siblings, 2 replies; 20+ messages in thread
From: Kim F. Storm @ 2005-11-15 22:24 UTC (permalink / raw)
Cc: Kevin Rodgers, emacs-devel
Paul Pogonyshev <pogonyshev@gmx.net> writes:
>> Which I think could be fixed like this:
>>
>> (let ((hard-newline "\n"))
>> ;; see set-hard-newline-properties:
>> (put-text-property 0 1 'hard t hard-newline)
>> (put-text-property 0 1 'rear-nonsticky '(hard) hard-newline)
>> ...
>> (insert header hard-newline))
We could put a generic definition into subr.el
which could then be used by any code needing a hard newline.
(defconst hard-newline
(propertize "\n"
'hard t 'rear-nonsticky '(hard)))
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-15 20:41 ` Paul Pogonyshev
2005-11-15 22:22 ` Kevin Rodgers
2005-11-15 22:24 ` Kim F. Storm
@ 2005-11-15 23:09 ` Stefan Monnier
2005-11-16 2:55 ` Chong Yidong
2005-11-15 23:33 ` Ryan Yeske
3 siblings, 1 reply; 20+ messages in thread
From: Stefan Monnier @ 2005-11-15 23:09 UTC (permalink / raw)
Cc: Kevin Rodgers, emacs-devel
> I think (and as far as I understood, Chong Yidong does too) that this is
> a welcoming message for future problems. You patch up a piece of code,
> while there are hundreds other lisp files, many of which insert newlines,
> some of which need to be hard. We probably need something generic. At
> the very least we need a convenience function to create a newline-string
> with the necessary properties already set, so we don't have to go over
> the lines above each time.
Maybe longlines-mode could provide a variable
"longlines-inserted-LF-are-hard" and then use it in an
after-change-functions hook to mark all inserted LF as hard when that
variable is non-nil.
I'd guess that the variable should be non-nil by default and only bound to
nil at a few specific spots, hopefully all of them in longlines.el.
Stefan
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-15 23:09 ` Stefan Monnier
@ 2005-11-16 2:55 ` Chong Yidong
2005-11-16 4:27 ` Stefan Monnier
2005-11-16 22:01 ` Richard M. Stallman
0 siblings, 2 replies; 20+ messages in thread
From: Chong Yidong @ 2005-11-16 2:55 UTC (permalink / raw)
Cc: Kevin Rodgers, emacs-devel, Paul Pogonyshev
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> Maybe longlines-mode could provide a variable
> "longlines-inserted-LF-are-hard" and then use it in an
> after-change-functions hook to mark all inserted LF as hard when that
> variable is non-nil.
>
> I'd guess that the variable should be non-nil by default and only bound to
> nil at a few specific spots, hopefully all of them in longlines.el.
The problem with using an after-change-function is that the function
is only told that the text was changed in a particular region, not
what the change was. There is no way to tell whether a soft newline
encountered in that region is a legit soft newline, or one produced by
an (insert "foo\n") call.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-16 2:55 ` Chong Yidong
@ 2005-11-16 4:27 ` Stefan Monnier
2005-11-16 22:01 ` Richard M. Stallman
1 sibling, 0 replies; 20+ messages in thread
From: Stefan Monnier @ 2005-11-16 4:27 UTC (permalink / raw)
Cc: Kevin Rodgers, Paul Pogonyshev, emacs-devel
>> Maybe longlines-mode could provide a variable
>> "longlines-inserted-LF-are-hard" and then use it in an
>> after-change-functions hook to mark all inserted LF as hard when that
>> variable is non-nil.
>>
>> I'd guess that the variable should be non-nil by default and only bound to
>> nil at a few specific spots, hopefully all of them in longlines.el.
> The problem with using an after-change-function is that the function
> is only told that the text was changed in a particular region, not
> what the change was. There is no way to tell whether a soft newline
> encountered in that region is a legit soft newline, or one produced by
> an (insert "foo\n") call.
If the `len' argument to the after-change-function is zero, it means it's
an insert. Now my suggestion is probably bogus indeed 'cause I know next to
nothing about longlines-mode. E.g. I'm not sure what you mean by "a legit
soft newline".
Stefan
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-16 2:55 ` Chong Yidong
2005-11-16 4:27 ` Stefan Monnier
@ 2005-11-16 22:01 ` Richard M. Stallman
2005-11-16 22:11 ` Chong Yidong
2005-11-17 19:22 ` Kevin Rodgers
1 sibling, 2 replies; 20+ messages in thread
From: Richard M. Stallman @ 2005-11-16 22:01 UTC (permalink / raw)
Cc: ihs_4664, pogonyshev, monnier, emacs-devel
> Maybe longlines-mode could provide a variable
> "longlines-inserted-LF-are-hard" and then use it in an
> after-change-functions hook to mark all inserted LF as hard when that
> variable is non-nil.
>
> I'd guess that the variable should be non-nil by default and only bound to
> nil at a few specific spots, hopefully all of them in longlines.el.
The problem with using an after-change-function is that the function
is only told that the text was changed in a particular region, not
what the change was. There is no way to tell whether a soft newline
encountered in that region is a legit soft newline, or one produced by
an (insert "foo\n") call.
A before-change-function can record the old text, and the
after-change-function can compare the new text with it. That way it can
see whether newlines were inserted.
However, if we really want a feature that makes all inserted newlines hard,
it would be easier to implement that within `insert' itself.
Let me be a little more specific: this would be a variable
`insert-string-filters', normally bound to nil. insert_string (in
insdel.c) checks the value of insert-string-filters passed to it. If
non-nil, it makes use of it as follows:
I think the added generality of that feature would, in this case, be
a mistake. It would make things slower and harder to use.
If the hard-newline variable is enough to do the job,
I would rather stick to that idea. It is simpler and less risky.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-16 22:01 ` Richard M. Stallman
@ 2005-11-16 22:11 ` Chong Yidong
2005-11-17 19:22 ` Kevin Rodgers
1 sibling, 0 replies; 20+ messages in thread
From: Chong Yidong @ 2005-11-16 22:11 UTC (permalink / raw)
Cc: ihs_4664, emacs-devel, monnier, pogonyshev
> If the hard-newline variable is enough to do the job,
> I would rather stick to that idea. It is simpler and less risky.
OK, I'll do that.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-16 22:01 ` Richard M. Stallman
2005-11-16 22:11 ` Chong Yidong
@ 2005-11-17 19:22 ` Kevin Rodgers
2005-11-17 22:01 ` Paul Pogonyshev
1 sibling, 1 reply; 20+ messages in thread
From: Kevin Rodgers @ 2005-11-17 19:22 UTC (permalink / raw)
Richard M. Stallman wrote:
> If the hard-newline variable is enough to do the job,
> I would rather stick to that idea. It is simpler and less risky.
Wouldn't the easiest thing be to add a call to
(set-hard-newline-properties (point-min) (point)) after
mail-header-separator and its trailing newline have been inserted?
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-17 19:22 ` Kevin Rodgers
@ 2005-11-17 22:01 ` Paul Pogonyshev
2005-11-17 22:52 ` Kevin Rodgers
0 siblings, 1 reply; 20+ messages in thread
From: Paul Pogonyshev @ 2005-11-17 22:01 UTC (permalink / raw)
Cc: Kevin Rodgers
Kevin Rodgers wrote:
> Richard M. Stallman wrote:
> > If the hard-newline variable is enough to do the job,
> > I would rather stick to that idea. It is simpler and less risky.
>
> Wouldn't the easiest thing be to add a call to
> (set-hard-newline-properties (point-min) (point)) after
> mail-header-separator and its trailing newline have been inserted?
Maybe, but that defeats the intention of providing a generic solution.
Paul
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-17 22:01 ` Paul Pogonyshev
@ 2005-11-17 22:52 ` Kevin Rodgers
2005-11-18 15:28 ` Paul Pogonyshev
2005-11-19 1:55 ` Richard M. Stallman
0 siblings, 2 replies; 20+ messages in thread
From: Kevin Rodgers @ 2005-11-17 22:52 UTC (permalink / raw)
Paul Pogonyshev wrote:
>Kevin Rodgers wrote:
>>Wouldn't the easiest thing be to add a call to
>>(set-hard-newline-properties (point-min) (point)) after
>>mail-header-separator and its trailing newline have been inserted?
>
> Maybe, but that defeats the intention of providing a generic solution.
How is the set-hard-newline-properties function any less generic than
the hard-newline variable? (Remember, the variable proposed by Kim is
not a boolean that controls the behavior of the insert function; it is a
string that has to be explicitly passed to the insert function.)
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-17 22:52 ` Kevin Rodgers
@ 2005-11-18 15:28 ` Paul Pogonyshev
2005-11-19 1:55 ` Richard M. Stallman
1 sibling, 0 replies; 20+ messages in thread
From: Paul Pogonyshev @ 2005-11-18 15:28 UTC (permalink / raw)
Cc: Kevin Rodgers
Kevin Rodgers wrote:
> Paul Pogonyshev wrote:
> >Kevin Rodgers wrote:
> >>Wouldn't the easiest thing be to add a call to
> >>(set-hard-newline-properties (point-min) (point)) after
> >>mail-header-separator and its trailing newline have been inserted?
> >
> > Maybe, but that defeats the intention of providing a generic solution.
>
> How is the set-hard-newline-properties function any less generic than
> the hard-newline variable? (Remember, the variable proposed by Kim is
> not a boolean that controls the behavior of the insert function; it is a
> string that has to be explicitly passed to the insert function.)
Uh, sorry, I don't know how I was reading your message, but I managed to
seriously misread it.
Yes, `set-hard-newline-properties' looks fine as well, especially if it
is documented. But I think we should add that `hard-newline' constant
too. Sometimes you need to pass strings to various functions and don't
have a (clean) way to work directly with the buffer. In such cases the
constant is useful.
Paul
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-17 22:52 ` Kevin Rodgers
2005-11-18 15:28 ` Paul Pogonyshev
@ 2005-11-19 1:55 ` Richard M. Stallman
1 sibling, 0 replies; 20+ messages in thread
From: Richard M. Stallman @ 2005-11-19 1:55 UTC (permalink / raw)
Cc: emacs-devel
How is the set-hard-newline-properties function any less generic than
the hard-newline variable?
This question is a side issue, and not relevant to further work,
so I ask people please not to send any more mail about this.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-15 20:41 ` Paul Pogonyshev
` (2 preceding siblings ...)
2005-11-15 23:09 ` Stefan Monnier
@ 2005-11-15 23:33 ` Ryan Yeske
2005-11-16 2:49 ` Chong Yidong
3 siblings, 1 reply; 20+ messages in thread
From: Ryan Yeske @ 2005-11-15 23:33 UTC (permalink / raw)
Cc: ihs_4664, emacs-devel
> Which I think could be fixed like this:
>
> (let ((hard-newline "\n"))
> ;; see set-hard-newline-properties:
> (put-text-property 0 1 'hard t hard-newline)
> (put-text-property 0 1 'rear-nonsticky '(hard) hard-newline)
> ...
> (insert header hard-newline))
I think (and as far as I understood, Chong Yidong does too) that this is
a welcoming message for future problems. You patch up a piece of code,
while there are hundreds other lisp files, many of which insert newlines,
some of which need to be hard. We probably need something generic. At
the very least we need a convenience function to create a newline-string
with the necessary properties already set, so we don't have to go over
the lines above each time.
Doesn't (newline) insert the right kind of newline based on the value
of `use-hard-newlines'?
Ryan
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Longlines and insert
2005-11-15 23:33 ` Ryan Yeske
@ 2005-11-16 2:49 ` Chong Yidong
0 siblings, 0 replies; 20+ messages in thread
From: Chong Yidong @ 2005-11-16 2:49 UTC (permalink / raw)
Cc: ihs_4664, emacs-devel, Paul Pogonyshev
> I think (and as far as I understood, Chong Yidong does too) that this is
> a welcoming message for future problems. You patch up a piece of code,
> while there are hundreds other lisp files, many of which insert newlines,
> some of which need to be hard. We probably need something generic. At
> the very least we need a convenience function to create a newline-string
> with the necessary properties already set, so we don't have to go over
> the lines above each time.
>
> Doesn't (newline) insert the right kind of newline based on the value
> of `use-hard-newlines'?
`newline' does. The problem is Lisp code that does (insert "foo\n")
^ permalink raw reply [flat|nested] 20+ messages in thread