unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Longlines and insert
       [not found] <874q6fa1t0.wl%david.wallin@ul.ie>
@ 2005-11-15  2:12 ` Chong Yidong
  2005-11-15 19:00   ` Kevin Rodgers
  2005-11-16  3:02   ` Chong Yidong
  0 siblings, 2 replies; 20+ messages in thread
From: Chong Yidong @ 2005-11-15  2:12 UTC (permalink / raw)


I got a bug report from a user who had longlines-mode turned on for
text-mode and all its derivatives, and found that it didn't play well
with `M-x mail'.

(The fact that longlines was originally written as a hack is sadly
apparent when situations like this arise...)

> (add-hook 'text-mode-hook 'longlines-mode)
>
> I have to disable longlines in mail-mode-hook to reenable it in
> wl-mail-setup-hook. This seems to be because of some filling
> operations when mail-mode is initialized. Don't know, is this a
> problem with longlines or mail-mode?
>
> The second problem is bothering me more. It has to do with attaching
> a binary file when editing an email. It looks like a space is turned
> into a hard newline

The problem is that mail-setup inserts the header fields by calling

  (insert "blahblah\n")

The inserted newlines are not marked as hard, so longlines gets
confused.

I could fix this by going through sendmail.el and adding (newline) to
all these places.  But maybe a more wide-reaching solution is called
for.

One possibility is to define a new variable `insert-filters', to store
a list of filter functions to run on strings before they are inserted
(analogous to `buffer-substring-filters').

I don't know if this is too invasive a change, especially before a
release, and just for the sake of longlines mode.

What do people think?

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Longlines and insert
  2005-11-15  2:12 ` Longlines and insert Chong Yidong
@ 2005-11-15 19:00   ` Kevin Rodgers
  2005-11-15 20:41     ` Paul Pogonyshev
  2005-11-16  3:02   ` Chong Yidong
  1 sibling, 1 reply; 20+ messages in thread
From: Kevin Rodgers @ 2005-11-15 19:00 UTC (permalink / raw)


Chong Yidong wrote:
 > The problem is that mail-setup inserts the header fields by calling
 >
 >   (insert "blahblah\n")
 >
 > The inserted newlines are not marked as hard, so longlines gets
 > confused.
 >
 > I could fix this by going through sendmail.el and adding (newline) to
 > all these places.  But maybe a more wide-reaching solution is called
 > for.

How about a less invasive change?  The headers are actually inserted
like this:

(insert header "\n")

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))

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Longlines and insert
  2005-11-15 19:00   ` Kevin Rodgers
@ 2005-11-15 20:41     ` Paul Pogonyshev
  2005-11-15 22:22       ` Kevin Rodgers
                         ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: Paul Pogonyshev @ 2005-11-15 20:41 UTC (permalink / raw)
  Cc: Kevin Rodgers

Kevin Rodgers wrote:
> Chong Yidong wrote:
>  > The problem is that mail-setup inserts the header fields by calling
>  >
>  >   (insert "blahblah\n")
>  >
>  > The inserted newlines are not marked as hard, so longlines gets
>  > confused.
>  >
>  > I could fix this by going through sendmail.el and adding (newline) to
>  > all these places.  But maybe a more wide-reaching solution is called
>  > for.
> 
> How about a less invasive change?  The headers are actually inserted
> like this:
> 
> (insert header "\n")
> 
> 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.

Paul

^ 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
                         ` (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 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

* 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-15  2:12 ` Longlines and insert Chong Yidong
  2005-11-15 19:00   ` Kevin Rodgers
@ 2005-11-16  3:02   ` Chong Yidong
  1 sibling, 0 replies; 20+ messages in thread
From: Chong Yidong @ 2005-11-16  3:02 UTC (permalink / raw)


Chong Yidong <cyd@stupidchicken.com> writes:

> One possibility is to define a new variable `insert-filters', to store
> a list of filter functions to run on strings before they are inserted
> (analogous to `buffer-substring-filters').

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:

Like `buffer-substring-filters', `insert-string-filters' would contain
a list of function, each of which accepts a single argument, a string,
and returns a string.  The string argument is passed to the first
function in the list, and the return value of each function is passed
to the next.  The last return value is the one actually inserted.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Longlines and insert
  2005-11-15 22:24       ` Kim F. Storm
@ 2005-11-16  3:05         ` Chong Yidong
  2005-11-16 10:48         ` Richard M. Stallman
  1 sibling, 0 replies; 20+ messages in thread
From: Chong Yidong @ 2005-11-16  3:05 UTC (permalink / raw)
  Cc: Kevin Rodgers, emacs-devel, Paul Pogonyshev

> 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)))

This would work.  So, which approach should I use?

^ 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-15 22:24       ` Kim F. Storm
  2005-11-16  3:05         ` Chong Yidong
@ 2005-11-16 10:48         ` Richard M. Stallman
  1 sibling, 0 replies; 20+ messages in thread
From: Richard M. Stallman @ 2005-11-16 10:48 UTC (permalink / raw)
  Cc: ihs_4664, emacs-devel, pogonyshev

    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)))

I like that approach since it is painless and
certainly won't break anything.

^ 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

end of thread, other threads:[~2005-11-19  1:55 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <874q6fa1t0.wl%david.wallin@ul.ie>
2005-11-15  2:12 ` Longlines and insert Chong Yidong
2005-11-15 19:00   ` Kevin Rodgers
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-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
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
2005-11-15 23:33       ` Ryan Yeske
2005-11-16  2:49         ` Chong Yidong
2005-11-16  3:02   ` Chong Yidong

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).