summaryrefslogtreecommitdiff
path: root/.emacs.d/init-org.el
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2020-07-19 09:39:51 -0700
committerSean Whitton <spwhitton@spwhitton.name>2020-07-20 12:29:31 -0700
commit820ca2a27ae746bf9349112667f4136975cea743 (patch)
treeaf1e4fa62ccc509b0888f15801a9b34c1f33e4bd /.emacs.d/init-org.el
parentac42a516aacc03d889e563c15d634cee2552ac9b (diff)
downloaddotfiles-820ca2a27ae746bf9349112667f4136975cea743.tar.gz
tidy up adding and removing agenda files
Diffstat (limited to '.emacs.d/init-org.el')
-rw-r--r--.emacs.d/init-org.el68
1 files changed, 31 insertions, 37 deletions
diff --git a/.emacs.d/init-org.el b/.emacs.d/init-org.el
index 9170493c..44710b68 100644
--- a/.emacs.d/init-org.el
+++ b/.emacs.d/init-org.el
@@ -640,43 +640,6 @@ different occasions."
("u" "URI on clipboard" entry (file org-default-notes-file)
"* SOMEDAY [[%^{URI|%x}][%^{Title}]]" :immediate-finish t)))
-;;;; ---- adding and removing agenda files ----
-
-;;; the default C-c [ and C-c ] expand the directory ~/doc/org in the
-;;; org-agenda-files variable using the local path,
-;;; e.g. /meta/s/spw/doc/org, which is not good when init-custom.el is
-;;; held in git. So use alternative behaviour of storing the agenda
-;;; paths in a file (see documentation for `org-agenda-files'). Two
-;;; functions to do the work
-
-(defun spw--org-agenda-file-to-front ()
- (interactive)
- (let ((path (abbreviate-file-name buffer-file-name)))
- (with-current-buffer (find-file-noselect org-agenda-files)
- (save-excursion
- (goto-char (point-min))
- (if (not (search-forward path nil t))
- (progn
- (goto-char (point-max))
- (insert path)
- (save-buffer)
- (message "added")))))))
-(define-key org-mode-map "\C-c[" #'spw--org-agenda-file-to-front)
-
-(defun spw--org-remove-file ()
- (interactive)
- (let ((path (abbreviate-file-name buffer-file-name)))
- (with-current-buffer (find-file-noselect org-agenda-files)
- (save-excursion
- (goto-char (point-min))
- (if (search-forward path nil t)
- (progn
- (beginning-of-line)
- (kill-line 1)
- (save-buffer)
- (message "removed")))))))
-(define-key org-mode-map "\C-c]" #'spw--org-remove-file)
-
;;;; ---- hooks and bindings ----
;; auto-fill-mode
@@ -741,4 +704,35 @@ different occasions."
(org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
(define-key org-agenda-mode-map "&" #'spw/org-agenda-priority-filter)
+;;; the default C-c [ and C-c ] expand the directory ~/doc/org in the
+;;; org-agenda-files variable using the local path,
+;;; e.g. /meta/s/spw/doc/org, which is not good when init-custom.el is
+;;; held in git. So use alternative behaviour of storing the agenda
+;;; paths in a file (see documentation for `org-agenda-files'). Two
+;;; functions to do the work
+
+(defun spw/org-agenda-file-to-front ()
+ (interactive)
+ (let ((path (abbreviate-file-name buffer-file-name)))
+ (with-current-buffer (find-file-noselect org-agenda-files)
+ (save-excursion
+ (goto-char (point-min))
+ (unless (search-forward path nil t)
+ (goto-char (point-max))
+ (insert path)
+ (save-buffer)
+ (message "Added"))))))
+(define-key org-mode-map "\C-c[" #'spw/org-agenda-file-to-front)
+
+(defun spw/org-remove-file ()
+ (interactive)
+ (let ((path (abbreviate-file-name buffer-file-name)))
+ (with-current-buffer (find-file-noselect org-agenda-files)
+ (save-excursion
+ (goto-char (point-min))
+ (flush-lines (concat "^" path "$"))
+ (save-buffer)
+ (message "Removed")))))
+(define-key org-mode-map "\C-c]" #'spw/org-remove-file)
+
;;; init-org.el ends here