* Smart(er) word wrapping with org-mode and visual-line-mode
@ 2009-12-03 10:14 Matthew Dempsky
2009-12-03 14:23 ` Carsten Dominik
2010-01-06 15:25 ` Martin Pohlack
0 siblings, 2 replies; 8+ messages in thread
From: Matthew Dempsky @ 2009-12-03 10:14 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 895 bytes --]
While playing around with the different options for handling word
wrapping in org-mode, I decided to instead hack an extension that
improves visual-line-mode's word wrapping when used in conjunction
with org-mode. In particular, the mrd-org-smartwrap minor mode
automatically sets the `wrap-prefix' property on all section headlines
and plain list entries so that visual-line-mode's native word wrapping
looks identical to what careful and continual usage of TAB and M-q
should produce, without any of the quirks of using auto-fill-mode or
refill-mode.
Just thought I'd share in case anyone else found it useful / interesting.
Caveats: It's incompatible with org-indent-mode, doesn't do anything
to support org-adapt-indentation, and results in tables being word
wrapped. I've also noticed linum-mode causes it to go crazy if the
top visible line is the continuation of a soft wrapped line.
[-- Attachment #2: mrd-org-smartwrap.el --]
[-- Type: application/octet-stream, Size: 5457 bytes --]
;;; mrd-org-smartwrap.el --- Smart word-wrapping for org-mode
;; version 20091202
;; Matthew Dempsky
;;
;; Derived from org-indent.el:
;;
;; Copyright (C) 2009 Free Software Foundation, Inc.
;;
;; Author: Carsten Dominik <carsten at orgmode dot org>
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 6.33x
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;; XXX: Somehow re-enable truncate-lines for lines containing tables.
(require 'org-macs)
(require 'org-compat)
(require 'org)
(eval-when-compile
(require 'cl))
(defconst mrd-org-smartwrap-max 40
"Maximum indentation level")
(defvar mrd-org-smartwrap-strings nil
"Vector with all prefix strings.
It will be set in `mrd-org-smartwrap-initialize'.")
(defun mrd-org-smartwrap-initialize ()
"Initialize the prefix strings."
(unless mrd-org-smartwrap-strings
(setq mrd-org-smartwrap-strings
(make-vector (1+ mrd-org-smartwrap-max) nil))
(loop for i from 1 to mrd-org-smartwrap-max do
(aset mrd-org-smartwrap-strings i (make-string i ?\ )))))
;;;###autoload
(define-minor-mode mrd-org-smartwrap-mode
"When active, wrap text according to outline and list structure.
This mode is intended to be used with `visual-line-mode'.
Internally this works by adding `wrap-prefix' properties on
section headlines and plain list entries."
nil " sw" nil
(if (org-bound-and-true-p org-inhibit-startup)
(setq mrd-org-smartwrap-mode nil)
(if mrd-org-smartwrap-mode
(progn
(mrd-org-smartwrap-initialize)
(make-local-variable 'buffer-substring-filters)
(add-hook 'buffer-substring-filters
'mrd-org-smartwrap-remove-properties-from-string nil t)
(add-hook 'after-change-functions
'mrd-org-smartwrap-after-change nil t)
(save-restriction
(widen)
(mrd-org-smartwrap-add-properties (point-min) (point-max))))
(save-restriction
(widen)
(mrd-org-smartwrap-remove-properties (point-min) (point-max)))
(remove-hook 'buffer-substring-filters
'mrd-org-smartwrap-remove-properties-from-string t)
(remove-hook 'after-change-functions
'mrd-org-smartwrap-after-change t))))
;; The regexps here are based on org-outline-regexp and the regexps
;; from org-adaptive-fill-function.
(defconst mrd-org-smartwrap-outline-re
"^\\(\\*+ \\|[ \t]*\\([-*+] \\|[0-9]+[.)] \\)\\)"
"Outline or plain list regexp.")
(defun mrd-org-smartwrap-add-properties (beg end)
"Add `wrap-prefix' properties between BEG and END.
Assumes that BEG is at the beginning of a line."
(org-unmodified
(save-excursion
(goto-char beg)
;; XXX: Use the BOUND argument to RE-SEARCH-FORWARD?
(while (and (re-search-forward mrd-org-smartwrap-outline-re nil t)
(<= (point) end))
(beginning-of-line)
;; XXX: For definitions with terms that span multiple lines,
;; the result is somewhat peculiar; namely, the rest of the
;; term is indented 5 spaces as well. It might make sense to
;; indent all of the term (up and including the " :: ") just
;; past the bullet point, and then only indent the rest of the
;; string any further. Not sure.
;; XXX: Doesn't support org-description-max-indent being
;; ridiculously large... probably doesn't need to.
;; XXX: Doesn't support numbered definition lists: this matches
;; M-q's behavior, but not the syntax highlighting...
(let ((level (if (and (looking-at "[ \t]*\\([-*+] .*? :: \\)")
(> (- (match-end 1) (match-beginning 1))
org-description-max-indent))
(- (+ (match-beginning 1) 5) (match-beginning 0))
(- (match-end 0) (match-beginning 0)))))
(set-text-properties
(point-at-bol) (point-at-eol)
`(wrap-prefix ,(aref mrd-org-smartwrap-strings level))))
(end-of-line)))))
(defun mrd-org-smartwrap-remove-properties (beg end)
"Remove `wrap-prefix' properties between BEG and END."
(org-unmodified
(remove-text-properties beg end '(wrap-prefix nil))))
(defun mrd-org-smartwrap-remove-properties-from-string (string)
"Remove `wrap-prefix' properties between BEG and END."
(remove-text-properties 0 (length string)
'(wrap-prefix nil) string)
string)
(defun mrd-org-smartwrap-refresh-region (beg end)
"Refresh `wrap-prefix' properties between BEG and END.
Assumes that BEG is at the beginning of a line."
(mrd-org-smartwrap-remove-properties beg end)
(mrd-org-smartwrap-add-properties beg end))
(defun mrd-org-smartwrap-after-change (beg end len)
"Refresh `wrap-prefix' properties between BEG and END."
(mrd-org-smartwrap-refresh-region
(save-excursion (goto-char beg) (point-at-bol))
(save-excursion (goto-char end) (point-at-eol))))
(provide 'mrd-org-smartwrap)
;;; mrd-org-smartwrap.el ends here
[-- Attachment #3: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Smart(er) word wrapping with org-mode and visual-line-mode
2009-12-03 10:14 Smart(er) word wrapping with org-mode and visual-line-mode Matthew Dempsky
@ 2009-12-03 14:23 ` Carsten Dominik
2009-12-03 19:10 ` Matthew Dempsky
2010-01-06 15:25 ` Martin Pohlack
1 sibling, 1 reply; 8+ messages in thread
From: Carsten Dominik @ 2009-12-03 14:23 UTC (permalink / raw)
To: Matthew Dempsky; +Cc: emacs-orgmode
Hi Matthew,
this is nice, I might want to merge this into Org-mode in one way or
another - if you agree. Do you? Would you sign the papers?
- Carsten
On Dec 3, 2009, at 11:14 AM, Matthew Dempsky wrote:
> While playing around with the different options for handling word
> wrapping in org-mode, I decided to instead hack an extension that
> improves visual-line-mode's word wrapping when used in conjunction
> with org-mode. In particular, the mrd-org-smartwrap minor mode
> automatically sets the `wrap-prefix' property on all section headlines
> and plain list entries so that visual-line-mode's native word wrapping
> looks identical to what careful and continual usage of TAB and M-q
> should produce, without any of the quirks of using auto-fill-mode or
> refill-mode.
>
> Just thought I'd share in case anyone else found it useful /
> interesting.
>
> Caveats: It's incompatible with org-indent-mode, doesn't do anything
> to support org-adapt-indentation, and results in tables being word
> wrapped. I've also noticed linum-mode causes it to go crazy if the
> top visible line is the continuation of a soft wrapped line.
> <mrd-org-smartwrap.el>_______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
- Carsten
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Smart(er) word wrapping with org-mode and visual-line-mode
2009-12-03 14:23 ` Carsten Dominik
@ 2009-12-03 19:10 ` Matthew Dempsky
0 siblings, 0 replies; 8+ messages in thread
From: Matthew Dempsky @ 2009-12-03 19:10 UTC (permalink / raw)
To: Carsten Dominik; +Cc: emacs-orgmode
On Thu, Dec 3, 2009 at 6:23 AM, Carsten Dominik
<carsten.dominik@gmail.com> wrote:
> this is nice, I might want to merge this into Org-mode in one way or another
> - if you agree. Do you? Would you sign the papers?
Sure, it's GPLv3-derived, so do whatever you'd like with it. :)
And yeah, I'm willing to sign the FSF paperwork.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Smart(er) word wrapping with org-mode and visual-line-mode
2009-12-03 10:14 Smart(er) word wrapping with org-mode and visual-line-mode Matthew Dempsky
2009-12-03 14:23 ` Carsten Dominik
@ 2010-01-06 15:25 ` Martin Pohlack
2010-01-08 17:24 ` Carsten Dominik
1 sibling, 1 reply; 8+ messages in thread
From: Martin Pohlack @ 2010-01-06 15:25 UTC (permalink / raw)
To: Matthew Dempsky; +Cc: emacs-orgmode
Hi Matthew,
Matthew Dempsky wrote:
> While playing around with the different options for handling word
> wrapping in org-mode, I decided to instead hack an extension that
> improves visual-line-mode's word wrapping when used in conjunction
> with org-mode. In particular, the mrd-org-smartwrap minor mode
> automatically sets the `wrap-prefix' property on all section headlines
> and plain list entries so that visual-line-mode's native word wrapping
> looks identical to what careful and continual usage of TAB and M-q
> should produce, without any of the quirks of using auto-fill-mode or
> refill-mode.
>
> Just thought I'd share in case anyone else found it useful / interesting.
I just tried this out (only for headlines up to now) and it seems to
work great.
Are there any plans to integrate something like this into upstream?
Especially the wrapping of headlines would enable extensive tag usage.
Cheers,
Martin Pohlack
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Smart(er) word wrapping with org-mode and visual-line-mode
2010-01-06 15:25 ` Martin Pohlack
@ 2010-01-08 17:24 ` Carsten Dominik
2010-01-10 19:09 ` Martin Pohlack
0 siblings, 1 reply; 8+ messages in thread
From: Carsten Dominik @ 2010-01-08 17:24 UTC (permalink / raw)
To: Martin Pohlack; +Cc: emacs-orgmode
On Jan 6, 2010, at 4:25 PM, Martin Pohlack wrote:
> Hi Matthew,
>
> Matthew Dempsky wrote:
>> While playing around with the different options for handling word
>> wrapping in org-mode, I decided to instead hack an extension that
>> improves visual-line-mode's word wrapping when used in conjunction
>> with org-mode. In particular, the mrd-org-smartwrap minor mode
>> automatically sets the `wrap-prefix' property on all section
>> headlines
>> and plain list entries so that visual-line-mode's native word
>> wrapping
>> looks identical to what careful and continual usage of TAB and M-q
>> should produce, without any of the quirks of using auto-fill-mode or
>> refill-mode.
>>
>> Just thought I'd share in case anyone else found it useful /
>> interesting.
>
> I just tried this out (only for headlines up to now) and it seems to
> work great.
>
> Are there any plans to integrate something like this into upstream?
> Especially the wrapping of headlines would enable extensive tag usage.
I have been thinking about that, but not arrived at a conclusion. One
thing is the interaction with org-indent-mode. That mode already does
the wrapping for headlines correctly by adding `wrap-prefix', and it
will look really good if you set the variable word-wrap to t.
However, the showstoppers are the following:
1. I cannot bring myself to turn off truncate-lines, because it
messes up tables and code examples badly, and these are major
components of my work. I have actually put in a feature
request into Emacs for a property `truncate-line', to be
able to control this line by line. I got positive feedback,
but I don't know when any of the developers finds time
to implement it - I cannot do that myself.
2. Visual-line-mode is also a no go for me, I use keyboard
macros a lot and need to be able to rely on the fact that
[down] move the cursor into the next physical line.
So I am not sure how to handle this. We could turn Matthews
code into a module that users can turn on if they wish.
- Carsten
>
>
> Cheers,
> Martin Pohlack
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
- Carsten
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Smart(er) word wrapping with org-mode and visual-line-mode
2010-01-08 17:24 ` Carsten Dominik
@ 2010-01-10 19:09 ` Martin Pohlack
2010-01-10 21:07 ` Carsten Dominik
2010-01-15 7:25 ` Carsten Dominik
0 siblings, 2 replies; 8+ messages in thread
From: Martin Pohlack @ 2010-01-10 19:09 UTC (permalink / raw)
To: Carsten Dominik; +Cc: emacs-orgmode
Hi Carsten and Matthew,
On 08.01.2010 18:24, Carsten Dominik wrote:
> On Jan 6, 2010, at 4:25 PM, Martin Pohlack wrote:
>> I just tried this out (only for headlines up to now) and it seems to
>> work great.
>>
>> Are there any plans to integrate something like this into upstream?
>> Especially the wrapping of headlines would enable extensive tag usage.
>
> I have been thinking about that, but not arrived at a conclusion. One
> thing is the interaction with org-indent-mode. That mode already does
> the wrapping for headlines correctly by adding `wrap-prefix', and it
> will look really good if you set the variable word-wrap to t.
Ah, I wasn't aware of that. I think the documentation to org-indent
doesn't mention wrapping (14.6 A cleaner outline view). How about
something like this:
org-indent-mode also sets the wrap-prefix property, such that
visual-line-mode (or purely setting word-wrap) wraps long lines
(including headlines) correctly indented.
> However, the showstoppers are the following:
>
> 1. I cannot bring myself to turn off truncate-lines, because it
> messes up tables and code examples badly, and these are major
> components of my work.
Right, I haven't used it to much up to now.
> I have actually put in a feature
> request into Emacs for a property `truncate-line', to be
> able to control this line by line. I got positive feedback,
> but I don't know when any of the developers finds time
> to implement it - I cannot do that myself.
Awesome. This sounds like the way to go.
> 2. Visual-line-mode is also a no go for me, I use keyboard
> macros a lot and need to be able to rely on the fact that
> [down] move the cursor into the next physical line.
I sometimes like visual navigation in wrapped text and my own motion
commands. I have two commands to move visually explicitly (bound to
s-down, s-up (super-...)).
(defun next-visual-line (&optional arg try-vscroll)
(interactive "^p\np")
(let ((line-move-visual t))
(with-no-warnings
(next-line arg try-vscroll))))
(defun previous-visual-line (&optional arg try-vscroll)
(interactive "^p\np")
(let ((line-move-visual t))
(with-no-warnings
(previous-line arg try-vscroll))))
> So I am not sure how to handle this. We could turn Matthews
> code into a module that users can turn on if they wish.
I'm using Matthew's module right now for two reasons.
* I had some trouble configuring org-indent-mode to only handle
line-wrapping for headlines, i.e., it shall only set wrap-prefix and
do nothing else. It always wanted to indent my headlines and body
texts additionally. Is this possible?
* Also, emacs segfaulted deterministically after globally collapsing
all trees with org-indent-mode active. I have to look into this ...
Cheers,
Martin
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Smart(er) word wrapping with org-mode and visual-line-mode
2010-01-10 19:09 ` Martin Pohlack
@ 2010-01-10 21:07 ` Carsten Dominik
2010-01-15 7:25 ` Carsten Dominik
1 sibling, 0 replies; 8+ messages in thread
From: Carsten Dominik @ 2010-01-10 21:07 UTC (permalink / raw)
To: Martin Pohlack; +Cc: emacs-orgmode
On Jan 10, 2010, at 8:09 PM, Martin Pohlack wrote:
> Hi Carsten and Matthew,
>
> On 08.01.2010 18:24, Carsten Dominik wrote:
>> On Jan 6, 2010, at 4:25 PM, Martin Pohlack wrote:
>>> I just tried this out (only for headlines up to now) and it seems to
>>> work great.
>>>
>>> Are there any plans to integrate something like this into upstream?
>>> Especially the wrapping of headlines would enable extensive tag
>>> usage.
>>
>> I have been thinking about that, but not arrived at a conclusion.
>> One
>> thing is the interaction with org-indent-mode. That mode already
>> does
>> the wrapping for headlines correctly by adding `wrap-prefix', and it
>> will look really good if you set the variable word-wrap to t.
>
> Ah, I wasn't aware of that. I think the documentation to org-indent
> doesn't mention wrapping (14.6 A cleaner outline view). How about
> something like this:
>
> org-indent-mode also sets the wrap-prefix property, such that
> visual-line-mode (or purely setting word-wrap) wraps long lines
> (including headlines) correctly indented.
>
>> However, the showstoppers are the following:
>>
>> 1. I cannot bring myself to turn off truncate-lines, because it
>> messes up tables and code examples badly, and these are major
>> components of my work.
>
> Right, I haven't used it to much up to now.
>
>> I have actually put in a feature
>> request into Emacs for a property `truncate-line', to be
>> able to control this line by line. I got positive feedback,
>> but I don't know when any of the developers finds time
>> to implement it - I cannot do that myself.
>
> Awesome. This sounds like the way to go.
>
>> 2. Visual-line-mode is also a no go for me, I use keyboard
>> macros a lot and need to be able to rely on the fact that
>> [down] move the cursor into the next physical line.
>
> I sometimes like visual navigation in wrapped text and my own motion
> commands. I have two commands to move visually explicitly (bound to
> s-down, s-up (super-...)).
>
> (defun next-visual-line (&optional arg try-vscroll)
> (interactive "^p\np")
> (let ((line-move-visual t))
> (with-no-warnings
> (next-line arg try-vscroll))))
>
> (defun previous-visual-line (&optional arg try-vscroll)
> (interactive "^p\np")
> (let ((line-move-visual t))
> (with-no-warnings
> (previous-line arg try-vscroll))))
Jup, good way out.
>
>> So I am not sure how to handle this. We could turn Matthews
>> code into a module that users can turn on if they wish.
>
> I'm using Matthew's module right now for two reasons.
>
> * I had some trouble configuring org-indent-mode to only handle
> line-wrapping for headlines, i.e., it shall only set wrap-prefix and
> do nothing else. It always wanted to indent my headlines and body
> texts additionally. Is this possible?
>
> * Also, emacs segfaulted deterministically after globally collapsing
> all trees with org-indent-mode active. I have to look into this ...
You need a bleeding-edge Emacs. The official 23.1 release indeed
segfaults with this, but this bug has been fixed in the mean time.
- Carsten
>
> Cheers,
> Martin
- Carsten
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Smart(er) word wrapping with org-mode and visual-line-mode
2010-01-10 19:09 ` Martin Pohlack
2010-01-10 21:07 ` Carsten Dominik
@ 2010-01-15 7:25 ` Carsten Dominik
1 sibling, 0 replies; 8+ messages in thread
From: Carsten Dominik @ 2010-01-15 7:25 UTC (permalink / raw)
To: Martin Pohlack; +Cc: emacs-orgmode
On Jan 10, 2010, at 8:09 PM, Martin Pohlack wrote:
> Hi Carsten and Matthew,
>
> On 08.01.2010 18:24, Carsten Dominik wrote:
>> On Jan 6, 2010, at 4:25 PM, Martin Pohlack wrote:
>>> I just tried this out (only for headlines up to now) and it seems to
>>> work great.
>>>
>>> Are there any plans to integrate something like this into upstream?
>>> Especially the wrapping of headlines would enable extensive tag
>>> usage.
>>
>> I have been thinking about that, but not arrived at a conclusion.
>> One
>> thing is the interaction with org-indent-mode. That mode already
>> does
>> the wrapping for headlines correctly by adding `wrap-prefix', and it
>> will look really good if you set the variable word-wrap to t.
>
> Ah, I wasn't aware of that. I think the documentation to org-indent
> doesn't mention wrapping (14.6 A cleaner outline view). How about
> something like this:
>
> org-indent-mode also sets the wrap-prefix property, such that
> visual-line-mode (or purely setting word-wrap) wraps long lines
> (including headlines) correctly indented.
I have added this, thank you very much for not only asking
for improvement but actually formulating the sentence and
pointing out where it should go.
> [...]'m using Matthew's module right now for two reasons.
>
> * I had some trouble configuring org-indent-mode to only handle
> line-wrapping for headlines, i.e., it shall only set wrap-prefix and
> do nothing else. It always wanted to indent my headlines and body
> texts additionally. Is this possible?
Not yet. One way would be to make setting org-indent-indentation-per-
level
to 0, but that currently does not work.
>
> * Also, emacs segfaulted deterministically after globally collapsing
> all trees with org-indent-mode active. I have to look into this ...
>
> Cheers,
> Martin
- Carsten
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-01-15 7:55 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-03 10:14 Smart(er) word wrapping with org-mode and visual-line-mode Matthew Dempsky
2009-12-03 14:23 ` Carsten Dominik
2009-12-03 19:10 ` Matthew Dempsky
2010-01-06 15:25 ` Martin Pohlack
2010-01-08 17:24 ` Carsten Dominik
2010-01-10 19:09 ` Martin Pohlack
2010-01-10 21:07 ` Carsten Dominik
2010-01-15 7:25 ` Carsten Dominik
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.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).