emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: line/wrap-prefix patch


From: Stephen Berman
Subject: Re: line/wrap-prefix patch
Date: Sat, 05 Jul 2008 23:30:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

On Sat, 05 Jul 2008 09:52:17 +0900 Miles Bader <address@hidden> wrote:

> Stephen Berman <address@hidden> 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
<address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]