all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* "Soft" indent with visual-line-mode?
@ 2009-09-09 17:53 Tim Stewart
  2009-09-11 12:58 ` Stephen Berman
  0 siblings, 1 reply; 7+ messages in thread
From: Tim Stewart @ 2009-09-09 17:53 UTC (permalink / raw)
  To: help-gnu-emacs

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.

Thanks for the help,

-- 
-TimS

Tim Stewart
Stoo Research









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

* Re: "Soft" indent with visual-line-mode?
  2009-09-09 17:53 "Soft" indent with visual-line-mode? Tim Stewart
@ 2009-09-11 12:58 ` Stephen Berman
  2011-12-09 20:25   ` Tim Stewart
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Berman @ 2009-09-11 12:58 UTC (permalink / raw)
  To: help-gnu-emacs

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





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

* Re: "Soft" indent with visual-line-mode?
  2009-09-11 12:58 ` Stephen Berman
@ 2011-12-09 20:25   ` Tim Stewart
  2011-12-11 22:23     ` Stephen Berman
  0 siblings, 1 reply; 7+ messages in thread
From: Tim Stewart @ 2011-12-09 20:25 UTC (permalink / raw)
  To: help-gnu-emacs

On 09/11/09 08:58 AM, Stephen Berman wrote:
> 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)))))

It took me quite a while to try this.  Thank you Steve, it works quite 
well!  It was a little odd in Emacs Lisp mode, but seems to work great 
in more block-oriented code like Python, C, Perl, etc.

I also added the following to make it easy to enable globally and I 
tucked it away in my load-path as srb-adaptive-wrap-mode.el:


(defun turn-on-srb-adaptive-wrap-mode ()
   (srb-adaptive-wrap-mode 1))

(define-globalized-minor-mode global-srb-adaptive-wrap-mode
   srb-adaptive-wrap-mode turn-on-srb-adaptive-wrap-mode
   :lighter "")

(provide 'srb-adaptive-wrap-mode)


I also turn on the gutter arrows to make it more obvious what's happening:


; Let's show the fringe indicators when in visual-line-mode
(setq visual-line-fringe-indicators
        '(left-curly-arrow right-curly-arrow))


Thanks again!

-TimS

-- 
Tim Stewart
Stoo Research
+1 404 993 6492



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

* Re: "Soft" indent with visual-line-mode?
  2011-12-09 20:25   ` Tim Stewart
@ 2011-12-11 22:23     ` Stephen Berman
  2011-12-12  7:21       ` Tassilo Horn
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Berman @ 2011-12-11 22:23 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, 09 Dec 2011 15:25:22 -0500 Tim Stewart <tim@stoo.org> wrote:

> On 09/11/09 08:58 AM, Stephen Berman wrote:
>> 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)))))
>
> It took me quite a while to try this.  Thank you Steve, it works quite well!
> It was a little odd in Emacs Lisp mode, but seems to work great in more
> block-oriented code like Python, C, Perl, etc.
>
> I also added the following to make it easy to enable globally and I tucked it
> away in my load-path as srb-adaptive-wrap-mode.el:
>
>
> (defun turn-on-srb-adaptive-wrap-mode ()
>   (srb-adaptive-wrap-mode 1))
>
> (define-globalized-minor-mode global-srb-adaptive-wrap-mode
>   srb-adaptive-wrap-mode turn-on-srb-adaptive-wrap-mode
>   :lighter "")
>
> (provide 'srb-adaptive-wrap-mode)
>
>
> I also turn on the gutter arrows to make it more obvious what's happening:
>
>
> ; Let's show the fringe indicators when in visual-line-mode
> (setq visual-line-fringe-indicators
>        '(left-curly-arrow right-curly-arrow))
>
>
> Thanks again!
>
> -TimS

Glad you find it useful.  FYI, in the mean time a cleaner version has
been added to the GNU Emacs Lisp Package Archive (ELPA) as
adaptive-wrap-prefix.el.  This version leaves the fringe indicators
alone. (I removed them in my original version for aesthetic reasons, but
Stefan Monnier (who improved the code) pointed out that that's an
independent feature.)  You can download it via `M-x list-packages' (or
via the menu: Options->Manage Emacs Packages), or directly from this
URL:

http://bzr.savannah.gnu.org/lh/emacs/elpa/files/head:/packages/adaptive-wrap-prefix/

Steve Berman




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

* Re: "Soft" indent with visual-line-mode?
  2011-12-11 22:23     ` Stephen Berman
@ 2011-12-12  7:21       ` Tassilo Horn
  2011-12-12 11:47         ` Stephen Berman
  0 siblings, 1 reply; 7+ messages in thread
From: Tassilo Horn @ 2011-12-12  7:21 UTC (permalink / raw)
  To: help-gnu-emacs

Stephen Berman <stephen.berman@gmx.net> writes:

Hi Stephen,

> Glad you find it useful.  FYI, in the mean time a cleaner version has
> been added to the GNU Emacs Lisp Package Archive (ELPA) as
> adaptive-wrap-prefix.el.  This version leaves the fringe indicators
> alone. (I removed them in my original version for aesthetic reasons,
> but Stefan Monnier (who improved the code) pointed out that that's an
> independent feature.)  You can download it via `M-x list-packages' (or
> via the menu: Options->Manage Emacs Packages)

While I can see it on the emacs elpa branch (first as awp-mode, now as
adaptive-wrap-prefix), it's not listed here when I do M-x list-packages.
I guess, someone needs to do some manual step to update the list of
packages exported via http, right?

Bye,
Tassilo




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

* Re: "Soft" indent with visual-line-mode?
  2011-12-12  7:21       ` Tassilo Horn
@ 2011-12-12 11:47         ` Stephen Berman
  2011-12-17  9:17           ` Le Wang
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Berman @ 2011-12-12 11:47 UTC (permalink / raw)
  To: help-gnu-emacs

On Mon, 12 Dec 2011 08:21:23 +0100 Tassilo Horn <tassilo@member.fsf.org> wrote:

> Stephen Berman <stephen.berman@gmx.net> writes:
>
> Hi Stephen,
>
>> Glad you find it useful.  FYI, in the mean time a cleaner version has
>> been added to the GNU Emacs Lisp Package Archive (ELPA) as
>> adaptive-wrap-prefix.el.  This version leaves the fringe indicators
>> alone. (I removed them in my original version for aesthetic reasons,
>> but Stefan Monnier (who improved the code) pointed out that that's an
>> independent feature.)  You can download it via `M-x list-packages' (or
>> via the menu: Options->Manage Emacs Packages)
>
> While I can see it on the emacs elpa branch (first as awp-mode, now as
> adaptive-wrap-prefix), it's not listed here when I do M-x list-packages.
> I guess, someone needs to do some manual step to update the list of
> packages exported via http, right?

I guess so.  Sorry for the premature claim; I should have checked before
posting.

Steve Berman




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

* Re: "Soft" indent with visual-line-mode?
  2011-12-12 11:47         ` Stephen Berman
@ 2011-12-17  9:17           ` Le Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Le Wang @ 2011-12-17  9:17 UTC (permalink / raw)
  To: Stephen Berman; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 282 bytes --]

Didn't know I needed this until I saw it.  Thanks!

This should come with Emacs.

On Mon, Dec 12, 2011 at 7:47 PM, Stephen Berman <stephen.berman@gmx.net>wrote:

>
> I guess so.  Sorry for the premature claim; I should have checked before
> posting.
>
> Steve Berman
>
>
>


-- 
Le

[-- Attachment #2: Type: text/html, Size: 617 bytes --]

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

end of thread, other threads:[~2011-12-17  9:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-09 17:53 "Soft" indent with visual-line-mode? Tim Stewart
2009-09-11 12:58 ` Stephen Berman
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

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.