unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: emacs-devel@gnu.org
Subject: Re: line/wrap-prefix patch
Date: Sat, 05 Jul 2008 23:30:50 +0200	[thread overview]
Message-ID: <87bq1cggs5.fsf@escher.local.home> (raw)
In-Reply-To: 87d4lt5f0e.fsf@catnip.gol.com

On Sat, 05 Jul 2008 09:52:17 +0900 Miles Bader <miles@gnu.org> wrote:

> Stephen Berman <stephen.berman@gmx.net> writes:
>>> To get varying prefixes, you can use the `wrap-prefix' text property.
>>
>> Yes, I see this when I evaluate e.g. (put-text-property (point) (1+
>> (point)) 'wrap-prefix "    ") with the cursor on the first character of
>> a wrapped word.  Is this the right way to use this text property?
>
> You can put the property over the entire region of text that the
> wrap-prefix applies to; there's no need to know which words will
> actually get wrapped.

Ah, thank you, that didn't occur to me.

[...]
> The "right" indendation depends only on the text following the
> preceding _hard_ line-start, i.e, the preceding "non-wrap prefix".
[...]
> The tricky part is getting the wrap-prefix "       " by examining the
> current non-wrap prefix, "     - " in this case.  Currently there's no
> way of having the display engine do it, so one could alternatively have
> a font-lock-like mechanism that turned hard paragraph prefixes into
> wrap-prefix text properties.

On Fri, 04 Jul 2008 17:25:15 -0400 Stefan Monnier
<monnier@iro.umontreal.ca> wrote: 

> I'd expect it to be a job for jit-lock.

Thanks to both of you for these suggestions.  The following seems to
DTRT, at least according to my minimal testing; no doubt it could be
improved:

(defun srb-adaptive-indent (beg end)
  "Indent the region between BEG and END with adaptive filling."
  (goto-char beg)
  (let ((lbp (line-beginning-position))
	(lep (line-end-position)))
    (put-text-property lbp lep 'wrap-prefix (fill-context-prefix lbp lep)))
  (while (re-search-forward "\n" (point-max) t)
    (forward-char)
    (let ((lbp (line-beginning-position))
	  (lep (line-end-position)))
      (put-text-property lbp lep 'wrap-prefix (fill-context-prefix lbp lep)))))

(define-minor-mode srb-adaptive-wrap-mode
  "Wrap the buffer text with adaptive filling."
  :lighter ""
  (save-excursion
    (save-restriction
      (widen)
      (let ((buffer-undo-list t)
	    (inhibit-read-only t)
	    (mod (buffer-modified-p)))
	(if srb-adaptive-wrap-mode
	    (progn
	      (setq word-wrap t)
	      (unless (member '(continuation) fringe-indicator-alist)
		(push '(continuation) fringe-indicator-alist))
	      (jit-lock-register 'srb-adaptive-indent))
	  (jit-lock-unregister 'srb-adaptive-indent)
	  (remove-text-properties (point-min) (point-max) '(wrap-prefix pref))
	  (setq fringe-indicator-alist
		(delete '(continuation) fringe-indicator-alist))
	  (setq word-wrap nil))
	(set-buffer-modified-p mod)))))

Miles continued:

>> *********
>> I was really hoping you would respond to the display problem at
>> window-start.  I find it very dissatisfying to regard this as a
>> "misfeature" of Emacs redisplay and leave it that, as RMS seemed to
>> conclude was the only course to take.
>
> I haven't been able the reproduce it so far, so I need to try to do so
> more thoroughly.  I'll try to do so this weekend.

Do you use a proportional font?  I always used a monospaced font (mostly
Dejavu Sans Mono) and with that the recipe I gave is reliable.  But I
just tried it with a proportional font (Dejavu Sans), and to my surprise
my recipe failed, i.e. the indentation remained visible at window-start.
No idea why fixed and proportional fonts differ here.

Steve Berman





  reply	other threads:[~2008-07-05 21:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-30  3:38 line/wrap-prefix patch Miles Bader
2008-06-30  4:18 ` Miles Bader
2008-07-01  0:36   ` Miles Bader
2008-07-01  4:52     ` Chong Yidong
2008-07-01  5:38       ` Miles Bader
2008-07-01 14:10         ` Chong Yidong
2008-07-01 22:19 ` Stephen Berman
2008-07-03  4:19   ` Miles Bader
2008-07-04 20:50     ` Stephen Berman
2008-07-04 21:25       ` Stefan Monnier
2008-07-05  0:52       ` Miles Bader
2008-07-05 21:30         ` Stephen Berman [this message]
2008-07-06  1:05           ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bq1cggs5.fsf@escher.local.home \
    --to=stephen.berman@gmx.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).