From: Stephen Berman <stephen.berman@gmx.net>
To: help-gnu-emacs@gnu.org
Subject: Re: "Soft" indent with visual-line-mode?
Date: Fri, 11 Sep 2009 14:58:53 +0200 [thread overview]
Message-ID: <87ab11zlgy.fsf@escher.local.home> (raw)
In-Reply-To: 8CAC7B1B-0C66-4D38-B474-1C4150419B22@stoo.org
On Wed, 9 Sep 2009 13:53:58 -0400 Tim Stewart <tim@stoo.org> wrote:
> Hello Emacs Help,
>
> I like the idea of using longlines-mode or visual-line-mode to spend less time
> formatting code as I write. However, it is not useful to me when the wrapped
> lines start in the first column and break up the flow of the code.
>
> As an example, this is what I get now with a line that is indented 4 spaces.
> This is all one line, wrapped by the editor for me:
>
> This is a test of the emergency broadcast system. This is only a test. In
> the event of a real emergency, your head would have exploded.
>
> And this is what I want:
>
> This is a test of the emergency broadcast system. This is only a test. In
> the event of a real emergency, your head would have exploded.
>
> I've heard this referred to as a "soft" indent. I believe that Visual
> SlickEdit 9 and Kate both support this feature if you'd like other examples.
>
> Does anyone know of a feature or add-on for Emacs that can accomplish this?
> I've scoured the 'Tubes and can't find anything.
The following code might do what you want, though it might need some
tweaking. (To use it, evaluate it and call the minor mode manually or
add it to appropriate mode hooks.)
Steve Berman
(defun srb-adaptive-indent (beg end)
"Indent the region between BEG and END with adaptive filling."
(goto-char beg)
(while
(let ((lbp (line-beginning-position))
(lep (line-end-position)))
(put-text-property lbp lep 'wrap-prefix (fill-context-prefix lbp lep))
(search-forward "\n" end t))))
(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))
(restore-buffer-modified-p mod)))))
next prev parent reply other threads:[~2009-09-11 12:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-09 17:53 "Soft" indent with visual-line-mode? Tim Stewart
2009-09-11 12:58 ` Stephen Berman [this message]
2011-12-09 20:25 ` Tim Stewart
2011-12-11 22:23 ` Stephen Berman
2011-12-12 7:21 ` Tassilo Horn
2011-12-12 11:47 ` Stephen Berman
2011-12-17 9:17 ` Le Wang
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ab11zlgy.fsf@escher.local.home \
--to=stephen.berman@gmx.net \
--cc=help-gnu-emacs@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.