unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Tassilo Horn <tassilo@member.fsf.org>
Cc: Eli Zaretskii <eliz@gnu.org>,
	Stephen Berman <stephen.berman@gmx.net>,
	emacs-devel@gnu.org
Subject: Re: Indentation and visual-line-mode
Date: Fri, 25 Nov 2011 09:52:19 -0500	[thread overview]
Message-ID: <jwvfwhcgtsz.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87sjlc2tpw.fsf@tsdh.uni-koblenz.de> (Tassilo Horn's message of "Fri, 25 Nov 2011 14:54:19 +0100")

>>> (assuming you never want to change the indentation during editing).
>> A while ago there was a thread about implementing a minor mode to get
>> visual indentation with wrap-prefix using fill-context-prefix, in
>> which I proposed an adaptation of the above; see
>> <http://permalink.gmane.org/gmane.emacs.devel/125268>.  AFAIK there
>> was no followup to my proposal.

Indeed I didn't find the time to look at it and it ended up on my long
list of "things to do when hell finally freezes over".

> I've just tried that code, and it's exactly what I've been looking for.

I've just looked at it and it looks really nice and simple.
It can even be simplified further (see below).

Sadly, this can't be generalized to programming languages, in the sense
that you can't use foo-indent-calculate to set a wrap-prefix property
since the wrap-prefix to use depends on the place where the line
is wrapped.

> I'd appreciate if that feature would ship with Emacs.

It's too late for 24.1, but I've added it (under name "awp-mode.el"
which provides adaptive-wrap-prefix-mode) to ELPA.


        Stefan


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

(define-minor-mode srb-adaptive-wrap-mode
  "Wrap the buffer text with adaptive filling."
  :lighter ""
  (if srb-adaptive-wrap-mode
      (jit-lock-register #'srb-adaptive-indent)
    (jit-lock-unregister #'srb-adaptive-indent)
    (with-silent-modifications
      (save-restriction
        (widen)
        (remove-text-properties (point-min) (point-max) '(wrap-prefix nil))))))



  reply	other threads:[~2011-11-25 14:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-25  9:34 Indentation and visual-line-mode Tassilo Horn
2011-11-25 11:52 ` Eli Zaretskii
2011-11-25 12:38   ` Stephen Berman
2011-11-25 13:54     ` Tassilo Horn
2011-11-25 14:52       ` Stefan Monnier [this message]
2011-11-25 14:58         ` Lennart Borgman
2011-11-25 15:15         ` Tassilo Horn
2011-11-25 13:49 ` Lennart Borgman
2011-11-25 14:36   ` Tassilo Horn
2011-11-25 14:47     ` Lennart Borgman
2011-11-25 15:37       ` Juanma Barranquero
2011-11-25 15:46         ` Lennart Borgman
2011-11-25 14:00 ` 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=jwvfwhcgtsz.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=stephen.berman@gmx.net \
    --cc=tassilo@member.fsf.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).