summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2012-07-05 16:35:56 +0200
committerBastien Guerry <bzg@altern.org>2012-07-05 16:35:56 +0200
commita6e4dcfb4d2bb76c73d59189ff7491c1c21eb8fe (patch)
treeda6b1a25b401a38632e3e488334bd3ffe8dea382
parent820803ab9571ff0f9dae5219a9e8dbeeef8bc5ef (diff)
downloadorg-mode-a6e4dcfb4d2bb76c73d59189ff7491c1c21eb8fe.tar.gz
org.el: `org-toggle-heading' skips comments and returns a message when nothing has been done.
* org.el (org-at-comment-p): New function. (org-toggle-heading): Use `org-at-comment-p' to skip comments. Thanks to Charlie Millar for raising this issue.
-rw-r--r--lisp/org.el22
1 files changed, 16 insertions, 6 deletions
diff --git a/lisp/org.el b/lisp/org.el
index b89889d..6c308dd 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19139,9 +19139,10 @@ stars to add."
(lambda (pos)
(save-excursion
(goto-char pos)
+ (while (org-at-comment-p) (forward-line))
(skip-chars-forward " \r\t\n")
(point-at-bol)))))
- beg end)
+ beg end toggled)
;; Determine boundaries of changes. If a universal prefix has
;; been given, put the list in a region. If region ends at a bol,
;; do not consider the last line to be in the region.
@@ -19166,7 +19167,8 @@ stars to add."
((org-at-heading-p)
(while (< (point) end)
(when (org-at-heading-p t)
- (looking-at org-outline-regexp) (replace-match ""))
+ (looking-at org-outline-regexp) (replace-match "")
+ (setq toggled t))
(forward-line)))
;; Case 2. Started at an item: change items into headlines.
;; One star will be added by `org-list-to-subtree'.
@@ -19194,7 +19196,8 @@ stars to add."
(org-list-to-subtree
(org-list-parse-list t)
'(:istart (concat stars add-stars (funcall get-stars depth))
- :icount (concat stars add-stars (funcall get-stars depth))))))))
+ :icount (concat stars add-stars (funcall get-stars depth)))))))
+ (setq toggled t))
(forward-line))))
;; Case 3. Started at normal text: make every line an heading,
;; skipping headlines and items.
@@ -19210,10 +19213,11 @@ stars to add."
(t "*"))) ; inside heading, oddeven
(rpl (concat stars add-stars " ")))
(while (< (point) end)
- (when (and (not (org-at-heading-p)) (not (org-at-item-p))
+ (when (and (not (or (org-at-heading-p) (org-at-item-p) (org-at-comment-p)))
(looking-at "\\([ \t]*\\)\\(\\S-\\)"))
- (replace-match (concat rpl (match-string 2))))
- (forward-line)))))))))
+ (replace-match (concat rpl (match-string 2))) (setq toggled t))
+ (forward-line)))))))
+ (unless toggled (message "Cannot toggle heading from here"))))
(defun org-meta-return (&optional arg)
"Insert a new heading or wrap a region in a table.
@@ -21208,6 +21212,12 @@ This version does not only check the character property, but also
;; Compatibility alias with Org versions < 7.8.03
(defalias 'org-on-heading-p 'org-at-heading-p)
+(defun org-at-comment-p nil
+ "Is cursor in a line starting with a # character?"
+ (save-excursion
+ (beginning-of-line)
+ (looking-at "^#")))
+
(defun org-at-drawer-p nil
"Is cursor at a drawer keyword?"
(save-excursion