summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-10-16 20:18:57 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-10-16 21:11:06 +0200
commit8f96754932e8be63335c8565cec2d34f46f54078 (patch)
tree4435e887839642917a42b6d92d5260733b7a5dc7
parent1fb3cca7c08ec1a608b8bd8d1ff627250a463a3e (diff)
downloadorg-mode-8f96754932e8be63335c8565cec2d34f46f54078.tar.gz
Do not call `end-of-visual-line' when moving to the end of line
* lisp/org.el (org-end-of-line): Do not call `end-of-visual-line' when moving to the end of line. Also improve behaviour on elements that can be hidden. * testing/lisp/test-org.el: Add tests.
-rw-r--r--lisp/org.el68
-rw-r--r--testing/lisp/test-org.el37
2 files changed, 70 insertions, 35 deletions
diff --git a/lisp/org.el b/lisp/org.el
index c91695b..932f5b3 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -21304,45 +21304,43 @@ beyond the end of the headline."
(defun org-end-of-line (&optional arg)
"Go to the end of the line.
-If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
-first attempt, and only move to after the tags when the cursor is already
-beyond the end of the headline."
+If this is a headline, and `org-special-ctrl-a/e' is set, ignore
+tags on the first attempt, and only move to after the tags when
+the cursor is already beyond the end of the headline."
(interactive "P")
- (let ((special (if (consp org-special-ctrl-a/e)
- (cdr org-special-ctrl-a/e)
- org-special-ctrl-a/e)))
+ (let ((special (if (consp org-special-ctrl-a/e) (cdr org-special-ctrl-a/e)
+ org-special-ctrl-a/e))
+ (type (org-element-type
+ (save-excursion (beginning-of-line) (org-element-at-point)))))
(cond
- ((or (not special) arg
- (not (or (org-at-heading-p) (org-at-item-p) (org-at-drawer-p))))
+ ((or (not special) arg)
(call-interactively
- (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
- ((fboundp 'move-end-of-line) 'move-end-of-line)
- (t 'end-of-line))))
- ((org-at-heading-p)
+ (if (fboundp 'move-end-of-line) 'move-end-of-line 'end-of-line)))
+ ((memq type '(headline inlinetask))
(let ((pos (point)))
- (beginning-of-line 1)
- (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*\\)?$"))
- (if (eq special t)
- (if (or (< pos (match-beginning 1))
- (= pos (match-end 0)))
- (goto-char (match-beginning 1))
- (goto-char (match-end 0)))
- (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
- (goto-char (match-end 0))
- (goto-char (match-beginning 1))))
- (call-interactively (if (fboundp 'move-end-of-line)
- 'move-end-of-line
- 'end-of-line)))))
- ((org-at-drawer-p)
- (move-end-of-line 1)
- (when (overlays-at (1- (point))) (backward-char 1)))
- ;; At an item: Move before any hidden text.
- (t (call-interactively
- (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
- ((fboundp 'move-end-of-line) 'move-end-of-line)
- (t 'end-of-line)))))
- (org-no-warnings
- (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
+ (beginning-of-line 1)
+ (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*\\)?$"))
+ (if (eq special t)
+ (if (or (< pos (match-beginning 1)) (= pos (match-end 0)))
+ (goto-char (match-beginning 1))
+ (goto-char (match-end 0)))
+ (if (or (< pos (match-end 0))
+ (not (eq this-command last-command)))
+ (goto-char (match-end 0))
+ (goto-char (match-beginning 1))))
+ (call-interactively
+ (if (fboundp 'move-end-of-line) 'move-end-of-line 'end-of-line)))))
+ ((memq type
+ '(center-block comment-block drawer dynamic-block example-block
+ export-block item plain-list property-drawer
+ quote-block special-block src-block verse-block))
+ ;; Never move past the ellipsis.
+ (or (eolp) (move-end-of-line 1))
+ (when (org-invisible-p2) (backward-char)))
+ (t
+ (call-interactively
+ (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)
(define-key org-mode-map "\C-e" 'org-end-of-line)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index feb0f2a..d333cfc 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -402,6 +402,43 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
;; Navigation
+(ert-deftest test-org/end-of-line ()
+ "Test `org-end-of-line' specifications."
+ ;; Standard test.
+ (should
+ (org-test-with-temp-text "Some text\nSome other text"
+ (progn (org-end-of-line) (eolp))))
+ ;; At an headline with special movement.
+ (should
+ (org-test-with-temp-text "* Headline :tag:"
+ (let ((org-special-ctrl-a/e t))
+ (and (progn (org-end-of-line) (looking-at " :tag:"))
+ (progn (org-end-of-line) (eolp))
+ (progn (org-end-of-line) (looking-at " :tag:"))))))
+ ;; At an headline without special movement.
+ (should
+ (org-test-with-temp-text "* Headline :tag:"
+ (let ((org-special-ctrl-a/e nil))
+ (and (progn (org-end-of-line) (eolp))
+ (progn (org-end-of-line) (eolp))))))
+ ;; At an headline, with reversed movement.
+ (should
+ (org-test-with-temp-text "* Headline :tag:"
+ (let ((org-special-ctrl-a/e 'reversed)
+ (this-command last-command))
+ (and (progn (org-end-of-line) (eolp))
+ (progn (org-end-of-line) (looking-at " :tag:"))))))
+ ;; At a block without hidden contents.
+ (should
+ (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
+ (progn (org-end-of-line) (eolp))))
+ ;; At a block with hidden contents.
+ (should-not
+ (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
+ (progn (org-hide-block-toggle)
+ (org-end-of-line)
+ (eolp)))))
+
(ert-deftest test-org/forward-element ()
"Test `org-forward-element' specifications."
;; 1. At EOB: should error.