emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode
@ 2012-11-06 12:30 Toby Cubitt
  2012-11-06 12:31 ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Toby Cubitt @ 2012-11-06 12:30 UTC (permalink / raw)
  To: emacs-orgmode

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

Subject line and commit message says it all.

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: tsc25@cantab.net
web:   www.dr-qubit.org

[-- Attachment #2: 0001-Make-org-end-of-line-respect-visual-line-mode.patch --]
[-- Type: text/x-patch, Size: 2334 bytes --]

From bca045ffd27d41630c52a67390767cd622544bb9 Mon Sep 17 00:00:00 2001
From: "Toby S. Cubitt" <tsc25@cantab.net>
Date: Tue, 6 Nov 2012 13:25:15 +0100
Subject: [PATCH] Make org-end-of-line respect visual-line-mode

* lisp/org.el (org-beginning-of-line, org-end-of-line): Use
beginning-of-visual-line and end-of-visual-line to move to
beginning/end of line in visual-line-mode.
---
 lisp/org.el |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 2aa70bd..4ce4ed3 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -21567,7 +21567,8 @@ beyond the end of the headline."
 		     (car org-special-ctrl-a/e)
 		   org-special-ctrl-a/e))
 	refpos)
-    (if (org-bound-and-true-p line-move-visual)
+    (if (or (org-bound-and-true-p visual-line-mode)
+	    (org-bound-and-true-p line-move-visual))
 	(beginning-of-visual-line 1)
       (beginning-of-line 1))
     (if (and arg (fboundp 'move-beginning-of-line))
@@ -21578,7 +21579,9 @@ beyond the end of the headline."
 	(if (org-truely-invisible-p)
 	    (while (and (not (bobp)) (org-truely-invisible-p))
 	      (backward-char 1)
-	      (beginning-of-line 1))
+	      (if (org-bound-and-true-p visual-line-mode)
+		  (beginning-of-visual-line 1)
+		  (beginning-of-line 1)))
 	  (forward-char 1))))
     (when special
       (cond
@@ -21633,7 +21636,8 @@ the cursor is already beyond the end of the headline."
     (cond
      ((or (not special) arg)
       (call-interactively
-       (if (fboundp 'move-end-of-line) 'move-end-of-line 'end-of-line)))
+       (if (org-bound-and-true-p visual-line-mode) 'end-of-visual-line
+	 (if (fboundp 'move-end-of-line) 'move-end-of-line 'end-of-line))))
      ((memq type '(headline inlinetask))
       (let ((pos (point)))
         (beginning-of-line 1)
@@ -21657,7 +21661,8 @@ the cursor is already beyond the end of the headline."
       (when (org-invisible-p2) (backward-char)))
      (t
       (call-interactively
-       (if (fboundp 'move-end-of-line) 'move-end-of-line 'end-of-line))))
+       (if (org-bound-and-true-p visual-line-mode) 'end-of-visual-line
+	 (if (fboundp 'move-end-of-line) 'move-end-of-line 'end-of-line)))))
     (org-no-warnings (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
 
 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
-- 
1.7.8.6


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

* Re: [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode
  2012-11-06 12:30 [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode Toby Cubitt
@ 2012-11-06 12:31 ` Nicolas Goaziou
  2012-11-06 12:47   ` Toby Cubitt
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2012-11-06 12:31 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Toby Cubitt <tsc25@cantab.net> writes:

> Subject line and commit message says it all.

`org-end-of-line' has been patched already. Is there a bug in
`org-beginning-of-line'?


Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode
  2012-11-06 12:31 ` Nicolas Goaziou
@ 2012-11-06 12:47   ` Toby Cubitt
  2012-11-06 17:02     ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Toby Cubitt @ 2012-11-06 12:47 UTC (permalink / raw)
  To: emacs-orgmode

On Tue, Nov 06, 2012 at 01:31:41PM +0100, Nicolas Goaziou wrote:
> Toby Cubitt <tsc25@cantab.net> writes:
> 
> > Subject line and commit message says it all.
> 
> `org-end-of-line' has been patched already. Is there a bug in
> `org-beginning-of-line'?

I forgot to pull and rebase before posting, so missed the recent
fix. Sorry for the noise.

org-beginning-of-line uses org-beginning-of-visual-line when
line-move-visual is enabled. I'm not sure if line-mode-visual can be
disabled when visual-line-mode is enabled. If so, org-beginning-of-line
should maybe test for either line-mode-visual *or* visual-line-mode.

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: tsc25@cantab.net
web:   www.dr-qubit.org

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

* Re: [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode
  2012-11-06 12:47   ` Toby Cubitt
@ 2012-11-06 17:02     ` Nicolas Goaziou
  2012-11-06 17:27       ` Toby Cubitt
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2012-11-06 17:02 UTC (permalink / raw)
  To: emacs-orgmode

Toby Cubitt <tsc25@cantab.net> writes:

> org-beginning-of-line uses org-beginning-of-visual-line when
> line-move-visual is enabled. I'm not sure if line-mode-visual can be
> disabled when visual-line-mode is enabled. If so, org-beginning-of-line
> should maybe test for either line-mode-visual *or* visual-line-mode.

`beginning-of-visual-line' either set locally `line-move-visual' to t or
use `vertical-motion', which doesn't care about `lime-move-visual'
value. Thus, as one could expect, `line-move-visual' has no effect on
horizontal scrolling.

IMO, checking this variable is a no-op.

Btw, if you plan to patch this area, could you provided tests for it
(see test-org/end-of-line in test-org.el)? As I can testify, there is
a high risk of regression in that area.


Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode
  2012-11-06 17:02     ` Nicolas Goaziou
@ 2012-11-06 17:27       ` Toby Cubitt
  2012-11-06 17:30         ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Toby Cubitt @ 2012-11-06 17:27 UTC (permalink / raw)
  To: emacs-orgmode

On Tue, Nov 06, 2012 at 06:02:40PM +0100, Nicolas Goaziou wrote:
> Toby Cubitt <tsc25@cantab.net> writes:
> 
> > org-beginning-of-line uses org-beginning-of-visual-line when
> > line-move-visual is enabled. I'm not sure if line-mode-visual can be
> > disabled when visual-line-mode is enabled. If so, org-beginning-of-line
> > should maybe test for either line-mode-visual *or* visual-line-mode.
> 
> `beginning-of-visual-line' either set locally `line-move-visual' to t or
> use `vertical-motion', which doesn't care about `lime-move-visual'
> value. Thus, as one could expect, `line-move-visual' has no effect on
> horizontal scrolling.
> 
> IMO, checking this variable is a no-op.

I'm confused. Which variable are you talking about here?

Anyway, I see that `visual-line-mode's sets `line-move-visual' to t
buffer-locally. So checking only `line-move-visual' in
`org-beginning-of-line' is fine...

...which strongly suggests that the recent fix to `org-end-of-line' is
wrong. Shouldn't it also be checking `line-move-visual' and not
`visual-line-mode', like `org-beginning-of-line'?

> Btw, if you plan to patch this area, could you provided tests for it
> (see test-org/end-of-line in test-org.el)? As I can testify, there is
> a high risk of regression in that area.

Thanks, I'll try to remember. Though I have no plans to patch anything
else in this area.

Cheers,
Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: tsc25@cantab.net
web:   www.dr-qubit.org

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

* Re: [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode
  2012-11-06 17:27       ` Toby Cubitt
@ 2012-11-06 17:30         ` Nicolas Goaziou
  2012-11-06 17:43           ` Toby Cubitt
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2012-11-06 17:30 UTC (permalink / raw)
  To: emacs-orgmode

Toby Cubitt <tsc25@cantab.net> writes:

> I'm confused. Which variable are you talking about here?

`line-move-visual'

> Anyway, I see that `visual-line-mode's sets `line-move-visual' to t
> buffer-locally. So checking only `line-move-visual' in
> `org-beginning-of-line' is fine...
>
> ...which strongly suggests that the recent fix to `org-end-of-line' is
> wrong. Shouldn't it also be checking `line-move-visual' and not
> `visual-line-mode', like `org-beginning-of-line'?

Doesn't `visual-line-mode' set C-e to `end-of-visual-line'? As I tried
to explain, unless I'm mistaken, `line-move-visual' has nothing to do
with beginning or end of current line.


Regards,

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

* Re: [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode
  2012-11-06 17:30         ` Nicolas Goaziou
@ 2012-11-06 17:43           ` Toby Cubitt
  2012-11-06 17:46             ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Toby Cubitt @ 2012-11-06 17:43 UTC (permalink / raw)
  To: emacs-orgmode

On Tue, Nov 06, 2012 at 06:30:47PM +0100, Nicolas Goaziou wrote:
> Toby Cubitt <tsc25@cantab.net> writes:
> 
> > I'm confused. Which variable are you talking about here?
> 
> `line-move-visual'
> 
> > Anyway, I see that `visual-line-mode's sets `line-move-visual' to t
> > buffer-locally. So checking only `line-move-visual' in
> > `org-beginning-of-line' is fine...
> >
> > ...which strongly suggests that the recent fix to `org-end-of-line' is
> > wrong. Shouldn't it also be checking `line-move-visual' and not
> > `visual-line-mode', like `org-beginning-of-line'?
> 
> Doesn't `visual-line-mode' set C-e to `end-of-visual-line'? As I tried
> to explain, unless I'm mistaken, `line-move-visual' has nothing to do
> with beginning or end of current line.

Aha! You may well be right. In which case why is `org-beginning-of-line'
doing this:

  (if (org-bound-and-true-p line-move-visual)
      (beginning-of-visual-line 1)
    (beginning-of-line 1))

Shouldn't it be doing this instead?

  (if (org-bound-and-true-p visual-line-mode)
      (beginning-of-visual-line 1)
    (beginning-of-line 1))

Or maybe I'm missing a subtle difference between org-beginning-of-line
and org-end-of-line...

Best,
Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: tsc25@cantab.net
web:   www.dr-qubit.org

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

* Re: [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode
  2012-11-06 17:43           ` Toby Cubitt
@ 2012-11-06 17:46             ` Nicolas Goaziou
  2012-11-06 18:46               ` Toby Cubitt
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2012-11-06 17:46 UTC (permalink / raw)
  To: emacs-orgmode

Toby Cubitt <tsc25@cantab.net> writes:

> Aha! You may well be right. In which case why is `org-beginning-of-line'
> doing this:
>
>   (if (org-bound-and-true-p line-move-visual)
>       (beginning-of-visual-line 1)
>     (beginning-of-line 1))
>
> Shouldn't it be doing this instead?
>
>   (if (org-bound-and-true-p visual-line-mode)
>       (beginning-of-visual-line 1)
>     (beginning-of-line 1))

Indeed. Do you want to provide a patch (you get bonus points for
regression tests)?

Regards,

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

* Re: [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode
  2012-11-06 17:46             ` Nicolas Goaziou
@ 2012-11-06 18:46               ` Toby Cubitt
  2012-11-06 19:41                 ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Toby Cubitt @ 2012-11-06 18:46 UTC (permalink / raw)
  To: emacs-orgmode

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

On Tue, Nov 06, 2012 at 06:46:27PM +0100, Nicolas Goaziou wrote:
> Toby Cubitt <tsc25@cantab.net> writes:
> 
> > Aha! You may well be right. In which case why is `org-beginning-of-line'
> > doing this:
> >
> >   (if (org-bound-and-true-p line-move-visual)
> >       (beginning-of-visual-line 1)
> >     (beginning-of-line 1))
> >
> > Shouldn't it be doing this instead?
> >
> >   (if (org-bound-and-true-p visual-line-mode)
> >       (beginning-of-visual-line 1)
> >     (beginning-of-line 1))
> 
> Indeed. Do you want to provide a patch (you get bonus points for
> regression tests)?

I guess you want regression tests for `end-of-line' with
`visual-line-mode' enabled? (There aren't any tests for beginning-of-line
in test-org.el currently, and the fix to org-beginning-of-line won't
actually change the behaviour, just make the code more correct.)

I've made an attempt in the attached patch, which also fixes
org-beginning-of-line as discussed.

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: tsc25@cantab.net
web:   www.dr-qubit.org

[-- Attachment #2: 0001-Bug-fix-in-org-beginning-of-line-visual-line-motion.patch --]
[-- Type: text/x-patch, Size: 2429 bytes --]

From c91b6bee12d27d43e4c2ba90c339c1b86010be67 Mon Sep 17 00:00:00 2001
From: "Toby S. Cubitt" <tsc25@cantab.net>
Date: Tue, 6 Nov 2012 19:06:26 +0100
Subject: [PATCH] Bug fix in org-beginning-of-line visual line motion

* lisp/org.el (org-beginning-of-line): check `visual-line-mode'
instead of `line-visual-mode' to determine whether to move by visual
lines.

* lisp/org.el (org-kill-line): use of org-bound-and-true-p macro.

* testing/lisp/test-org.el (test-org/end-of-line): add regression test
for `org-end-of-line' in `visual-line-mode' buffers.
---
 lisp/org.el              |    4 ++--
 testing/lisp/test-org.el |    7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index ad2863b..080b527 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -21577,7 +21577,7 @@ beyond the end of the headline."
 		     (car org-special-ctrl-a/e)
 		   org-special-ctrl-a/e))
 	refpos)
-    (if (org-bound-and-true-p line-move-visual)
+    (if (org-bound-and-true-p visual-line-mode)
 	(beginning-of-visual-line 1)
       (beginning-of-line 1))
     (if (and arg (fboundp 'move-beginning-of-line))
@@ -21704,7 +21704,7 @@ depending on context."
 		(not (y-or-n-p "Kill hidden subtree along with headline? ")))
 	    (error "C-k aborted - would kill hidden subtree")))
     (call-interactively
-     (if (and (boundp 'visual-line-mode) visual-line-mode) 'kill-visual-line 'kill-line)))
+     (if (org-bound-and-true-p visual-line-mode) 'kill-visual-line 'kill-line)))
    ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)[ \t]*$"))
     (kill-region (point) (match-beginning 1))
     (org-set-tags nil t))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 98957ac..a2115bf 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -477,6 +477,13 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
   (should
    (org-test-with-temp-text "Some text\nSome other text"
      (progn (org-end-of-line) (eolp))))
+  ;; Standard test with `visual-line-mode'.
+  (should
+   (org-test-with-temp-text
+       "A long line of text\nSome other text"
+     (progn (forward-char 2) (cl-dotimes (i 1000) (insert "very "))
+	    (visual-line-mode 1) (goto-char (point-min)) (org-end-of-line)
+	    (thing-at-point-looking-at "very"))))
   ;; At an headline with special movement.
   (should
    (org-test-with-temp-text "* Headline :tag:"
-- 
1.7.8.6


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

* Re: [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode
  2012-11-06 18:46               ` Toby Cubitt
@ 2012-11-06 19:41                 ` Nicolas Goaziou
  0 siblings, 0 replies; 10+ messages in thread
From: Nicolas Goaziou @ 2012-11-06 19:41 UTC (permalink / raw)
  To: emacs-orgmode

Toby Cubitt <tsc25@cantab.net> writes:

> I guess you want regression tests for `end-of-line' with
> `visual-line-mode' enabled? (There aren't any tests for beginning-of-line
> in test-org.el currently, and the fix to org-beginning-of-line won't
> actually change the behaviour, just make the code more correct.)

No, I meant tests for `org-beginning-of-line', since that's the function
you modified.

> I've made an attempt in the attached patch, which also fixes
> org-beginning-of-line as discussed.

Would you mind starting a test suite for that function?

> +   (org-test-with-temp-text
> +       "A long line of text\nSome other text"
> +     (progn (forward-char 2) (cl-dotimes (i 1000) (insert "very "))
> +	    (visual-line-mode 1) (goto-char (point-min)) (org-end-of-line)
> +	    (thing-at-point-looking-at "very"))))

`dotimes' is a function defined in subr.el. No need to call cl-dotimes.

Thanks for your work.


Regards,

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

end of thread, other threads:[~2012-11-06 19:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-06 12:30 [PATCH] Make org-[beginning|end]-of-line respect visual-line-mode Toby Cubitt
2012-11-06 12:31 ` Nicolas Goaziou
2012-11-06 12:47   ` Toby Cubitt
2012-11-06 17:02     ` Nicolas Goaziou
2012-11-06 17:27       ` Toby Cubitt
2012-11-06 17:30         ` Nicolas Goaziou
2012-11-06 17:43           ` Toby Cubitt
2012-11-06 17:46             ` Nicolas Goaziou
2012-11-06 18:46               ` Toby Cubitt
2012-11-06 19:41                 ` Nicolas Goaziou

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