New option: org-remember-delete-empty-lines-at-end

This default to t, so the default behavior of org-mode doesn't
change.  But the user might want to keep at least one blank line
at the end of the remembered subtree, this option lets her do it.
This commit is contained in:
Bastien Guerry 2009-07-18 10:09:40 +02:00
parent 57838f8286
commit 8a15fe867b
3 changed files with 37 additions and 20 deletions

View File

@ -1,3 +1,9 @@
2009-07-18 Bastien Guerry <bzg@altern.org>
* org-remember.el (org-remember-delete-empty-lines-at-end): New
option.
(org-remember-handler): Use the new option.
2009-07-17 James TD Smith <ahktenzero@mohorovi.cc> 2009-07-17 James TD Smith <ahktenzero@mohorovi.cc>
* org.el (org-tags-sort-function): New option for sorting tags. * org.el (org-tags-sort-function): New option for sorting tags.

View File

@ -197,6 +197,11 @@ calendar | %:type %:date"
(symbol :tag "Major mode")) (symbol :tag "Major mode"))
(function :tag "Perform a check against function"))))) (function :tag "Perform a check against function")))))
(defcustom org-remember-delete-empty-lines-at-end t
"Non-nil means clean up final empty lines in remember buffer."
:group 'org-remember
:type 'boolean)
(defcustom org-remember-before-finalize-hook nil (defcustom org-remember-before-finalize-hook nil
"Hook that is run right before a remember process is finalized. "Hook that is run right before a remember process is finalized.
The remember buffer is still current when this hook runs." The remember buffer is still current when this hook runs."
@ -746,6 +751,8 @@ The user is queried for the template."
(goto-char (match-beginning 0)) (goto-char (match-beginning 0))
(error "Target headline not found: %s" heading)))) (error "Target headline not found: %s" heading))))
;; FIXME (bzg): let's clean up of final empty lines happen only once
;; (see the org-remember-delete-empty-lines-at-end option below)
;;;###autoload ;;;###autoload
(defun org-remember-handler () (defun org-remember-handler ()
"Store stuff from remember.el into an org file. "Store stuff from remember.el into an org file.
@ -789,11 +796,12 @@ See also the variable `org-reverse-note-order'."
(goto-char (point-min)) (goto-char (point-min))
(while (looking-at "^[ \t]*\n\\|^##.*\n") (while (looking-at "^[ \t]*\n\\|^##.*\n")
(replace-match "")) (replace-match ""))
(goto-char (point-max)) (when org-remember-delete-empty-lines-at-end
(beginning-of-line 1) (goto-char (point-max))
(while (and (looking-at "[ \t]*$\\|##.*") (> (point) 1)) (beginning-of-line 1)
(delete-region (1- (point)) (point-max)) (while (and (looking-at "[ \t]*$\\|##.*") (> (point) 1))
(beginning-of-line 1)) (delete-region (1- (point)) (point-max))
(beginning-of-line 1)))
(catch 'quit (catch 'quit
(if org-note-abort (throw 'quit t)) (if org-note-abort (throw 'quit t))
(let* ((visitp (org-bound-and-true-p org-jump-to-target-location)) (let* ((visitp (org-bound-and-true-p org-jump-to-target-location))
@ -848,10 +856,11 @@ See also the variable `org-reverse-note-order'."
(setq current-prefix-arg nil) (setq current-prefix-arg nil)
;; Modify text so that it becomes a nice subtree which can be inserted ;; Modify text so that it becomes a nice subtree which can be inserted
;; into an org tree. ;; into an org tree.
(goto-char (point-min)) (when org-remember-delete-empty-lines-at-end
(if (re-search-forward "[ \t\n]+\\'" nil t) (goto-char (point-min))
;; remove empty lines at end (if (re-search-forward "[ \t\n]+\\'" nil t)
(replace-match "")) ;; remove empty lines at end
(replace-match "")))
(goto-char (point-min)) (goto-char (point-min))
(unless (looking-at org-outline-regexp) (unless (looking-at org-outline-regexp)
;; add a headline ;; add a headline
@ -862,11 +871,13 @@ See also the variable `org-reverse-note-order'."
(when org-adapt-indentation (when org-adapt-indentation
(while (re-search-forward "^" nil t) (while (re-search-forward "^" nil t)
(insert " ")))) (insert " "))))
(goto-char (point-min)) ;; Delete final empty lines
(if (re-search-forward "\n[ \t]*\n[ \t\n]*\\'" nil t) (when org-remember-delete-empty-lines-at-end
(replace-match "\n\n") (goto-char (point-min))
(if (re-search-forward "[ \t\n]*\\'") (if (re-search-forward "\n[ \t]*\n[ \t\n]*\\'" nil t)
(replace-match "\n"))) (replace-match "\n\n")
(if (re-search-forward "[ \t\n]*\\'")
(replace-match "\n"))))
(goto-char (point-min)) (goto-char (point-min))
(setq txt (buffer-string)) (setq txt (buffer-string))
(org-save-markers-in-region (point-min) (point-max)) (org-save-markers-in-region (point-min) (point-max))

View File

@ -16385,12 +16385,12 @@ This is like outline-next-sibling, but invisible headings are ok."
(outline-next-heading))) (outline-next-heading)))
(unless to-heading (unless to-heading
(if (memq (preceding-char) '(?\n ?\^M)) (if (memq (preceding-char) '(?\n ?\^M))
(progn (progn
;; Go to end of line before heading ;; Go to end of line before heading
(forward-char -1) (forward-char -1)
(if (memq (preceding-char) '(?\n ?\^M)) (if (memq (preceding-char) '(?\n ?\^M))
;; leave blank line before heading ;; leave blank line before heading
(forward-char -1)))))) (forward-char -1))))))
(point)) (point))
(defun org-show-subtree () (defun org-show-subtree ()