Refactor org-mode config
This commit is contained in:
parent
8537361e50
commit
b7d03fff52
3 changed files with 104 additions and 98 deletions
|
@ -1,57 +1,61 @@
|
||||||
;;; defuns-org-custom.el -- custom functions, links, etc. for Org-mode
|
;;; defuns-org-custom.el -- custom functions, links, etc. for Org-mode
|
||||||
|
|
||||||
(progn ;; Custom links
|
;;; Custom links
|
||||||
(defun narf--org-id-to-file (id dir &optional pattern)
|
(defun narf--org-id-to-file (id dir &optional pattern)
|
||||||
(let* ((glob (f-glob (format (concat "%s" (or pattern "%s-*.org")) dir id)))
|
(let* ((glob (f-glob (format (concat "%s" (or pattern "%s-*.org")) dir id)))
|
||||||
(glob-len (length glob)))
|
(glob-len (length glob)))
|
||||||
(when (zerop glob-len)
|
(when (zerop glob-len)
|
||||||
(user-error "Could not find file with that ID"))
|
(user-error "Could not find file with that ID"))
|
||||||
(car glob)))
|
(car glob)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/org-link-contact (id)
|
(defun narf/org-link-contact (id)
|
||||||
(org-open-file (narf--org-id-to-file id org-directory-contacts) t))
|
(org-open-file (narf--org-id-to-file id org-directory-contacts) t))
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/org-link-project (id)
|
(defun narf/org-link-project (id)
|
||||||
(org-open-file (narf--org-id-to-file id org-directory-projects) t))
|
(org-open-file (narf--org-id-to-file id org-directory-projects) t))
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/org-link-invoice (id)
|
(defun narf/org-link-invoice (id)
|
||||||
(org-open-file (narf--org-id-to-file id org-directory-invoices "%s.org") t))
|
(org-open-file (narf--org-id-to-file id org-directory-invoices "%s.org") t))
|
||||||
|
|
||||||
(defun narf-org-complete (type)
|
|
||||||
(let ((default-directory (symbol-value (intern (format "org-directory-%ss" type)))))
|
|
||||||
(let* ((file (org-iread-file-name ">>> "))
|
|
||||||
(match (s-match "^\\([0-9]+\\)[-.]" (f-filename file))))
|
|
||||||
(unless match
|
|
||||||
(user-error "Invalid file ID"))
|
|
||||||
(format "%s:%s" type (cadr match)))))
|
|
||||||
|
|
||||||
(defun org-contact-complete-link ()
|
|
||||||
(narf-org-complete "contact"))
|
|
||||||
(defun org-project-complete-link ()
|
|
||||||
(narf-org-complete "project"))
|
|
||||||
(defun org-invoice-complete-link ()
|
|
||||||
(narf-org-complete "invoice")))
|
|
||||||
|
|
||||||
(progn ;; Deft
|
|
||||||
;;;###autoload
|
|
||||||
(defun narf/deft-projects ()
|
|
||||||
(interactive)
|
|
||||||
(require 'deft)
|
|
||||||
(let ((deft-directory org-directory-projects))
|
|
||||||
(deft)))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/deft-contact ()
|
(defun narf/org-complete (type)
|
||||||
(interactive)
|
(let ((default-directory (symbol-value (intern (format "org-directory-%ss" type)))))
|
||||||
(require 'deft)
|
(let* ((file (org-iread-file-name ">>> "))
|
||||||
(let ((deft-directory org-directory-contacts))
|
(match (s-match "^\\([0-9]+\\)[-.]" (f-filename file))))
|
||||||
(deft)))
|
(unless match
|
||||||
|
(user-error "Invalid file ID"))
|
||||||
|
(format "%s:%s" type (cadr match)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/deft-invoices ())
|
(defun org-contact-complete-link ()
|
||||||
|
(narf/org-complete "contact"))
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/deft-writing ()))
|
(defun org-project-complete-link ()
|
||||||
|
(narf/org-complete "project"))
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-invoice-complete-link ()
|
||||||
|
(narf/org-complete "invoice"))
|
||||||
|
|
||||||
|
;;; Deft
|
||||||
|
;;;###autoload
|
||||||
|
(defun narf/deft-projects ()
|
||||||
|
(interactive)
|
||||||
|
(require 'deft)
|
||||||
|
(let ((deft-directory org-directory-projects))
|
||||||
|
(deft)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun narf/deft-contact ()
|
||||||
|
(interactive)
|
||||||
|
(require 'deft)
|
||||||
|
(let ((deft-directory org-directory-contacts))
|
||||||
|
(deft)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun narf/deft-invoices ())
|
||||||
|
;;;###autoload
|
||||||
|
(defun narf/deft-writing ())
|
||||||
|
|
||||||
(provide 'defuns-org-custom)
|
(provide 'defuns-org-custom)
|
||||||
;;; defuns-org-custom.el ends here
|
;;; defuns-org-custom.el ends here
|
||||||
|
|
|
@ -27,24 +27,14 @@
|
||||||
('above
|
('above
|
||||||
(narf/org-table-prepend-row-or-shift-up))))
|
(narf/org-table-prepend-row-or-shift-up))))
|
||||||
(t
|
(t
|
||||||
(org-back-to-heading)
|
(cl-case direction
|
||||||
(let ((first-p (org-first-sibling-p))
|
('below
|
||||||
(orig-char (point)))
|
(org-insert-heading-after-current))
|
||||||
(cl-case direction
|
('above
|
||||||
('below
|
(org-back-to-heading)
|
||||||
(org-insert-heading-after-current)
|
(org-insert-heading)))
|
||||||
(unless first-p
|
(when (org-element-property :todo-type context)
|
||||||
(save-excursion
|
(org-todo 'todo))))
|
||||||
(goto-char orig-char)
|
|
||||||
(evil-insert-newline-above)))
|
|
||||||
(save-excursion
|
|
||||||
(evil-insert-newline-below)))
|
|
||||||
('above
|
|
||||||
(save-excursion
|
|
||||||
(evil-insert-newline-below))
|
|
||||||
(unless first-p
|
|
||||||
(save-excursion
|
|
||||||
(evil-insert-newline-above))))))))
|
|
||||||
(evil-append-line 1)))
|
(evil-append-line 1)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -250,10 +240,11 @@ COUNT-FOOTNOTES? is non-nil."
|
||||||
(let ((path (if (string-match-p "^[/~]" dest)
|
(let ((path (if (string-match-p "^[/~]" dest)
|
||||||
dest
|
dest
|
||||||
(expand-file-name dest default-directory))))
|
(expand-file-name dest default-directory))))
|
||||||
(shell-command
|
(if (shell-command
|
||||||
(format "/usr/local/bin/pandoc '%s' -o '%s'"
|
(format "/usr/local/bin/pandoc '%s' -o '%s'"
|
||||||
(buffer-file-name) path))
|
(buffer-file-name) path))
|
||||||
(message "Done! Exported to: %s" path)))
|
(message "Done! Exported to: %s" path)
|
||||||
|
(user-error "Export failed"))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/org-remove-link ()
|
(defun narf/org-remove-link ()
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
:keymap (make-sparse-keymap) ; defines evil-org-mode-map
|
:keymap (make-sparse-keymap) ; defines evil-org-mode-map
|
||||||
:group 'evil-org)
|
:group 'evil-org)
|
||||||
|
|
||||||
(defvar org-directory (concat narf-dropbox-dir "org/"))
|
(defvar org-directory (expand-file-name "org/" narf-dropbox-dir))
|
||||||
(defvar org-directory-contacts (expand-file-name "work/contacts/" org-directory))
|
(defvar org-directory-contacts (expand-file-name "my/contacts/" org-directory))
|
||||||
(defvar org-directory-projects (expand-file-name "work/projects/" org-directory))
|
(defvar org-directory-projects (expand-file-name "my/projects/" org-directory))
|
||||||
(defvar org-directory-invoices (expand-file-name "work/invoices/" org-directory))
|
(defvar org-directory-invoices (expand-file-name "my/invoices/" org-directory))
|
||||||
|
|
||||||
(add-hook! org-load 'narf|org-init)
|
(add-hook! org-load 'narf|org-init)
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
|
|
||||||
org-capture-templates
|
org-capture-templates
|
||||||
'(("t" "TODO" entry
|
'(("t" "TODO" entry
|
||||||
(file+headline (concat org-directory "gtd.org") "Inbox")
|
(file+headline (concat org-directory "todo.org") "Inbox")
|
||||||
"** TODO %? %u")
|
"** TODO %? %u")
|
||||||
|
|
||||||
;; TODO Select file from org files
|
;; TODO Select file from org files
|
||||||
|
@ -66,13 +66,13 @@
|
||||||
;; "** %<%H:%M>: %? :unsorted:\n%i" :prepend t)
|
;; "** %<%H:%M>: %? :unsorted:\n%i" :prepend t)
|
||||||
|
|
||||||
("j" "Journal" entry
|
("j" "Journal" entry
|
||||||
(file+datetree (concat org-directory "personal/journal.org"))
|
(file+datetree (concat org-directory "journal.org"))
|
||||||
"** %<%H:%M>: %?\n%i" :prepend t)
|
"** %<%H:%M>: %?\n%i" :prepend t)
|
||||||
|
|
||||||
;; TODO Select file from notes folder
|
;; TODO Select file from notes folder
|
||||||
;; ("n" "Notes" entry
|
("n" "Notes" entry
|
||||||
;; (file "~/Dropbox/notes/trivia.org")
|
(file+headline (concat org-directory "notes.org") "Inbox")
|
||||||
;; "* %u %?\n%i" :prepend t)
|
"* %u %?\n%i" :prepend t)
|
||||||
|
|
||||||
("s" "Writing Scraps" entry
|
("s" "Writing Scraps" entry
|
||||||
(file+headline (concat org-directory "writing/scraps.org") "Unsorted")
|
(file+headline (concat org-directory "writing/scraps.org") "Unsorted")
|
||||||
|
@ -202,6 +202,7 @@ will function properly."
|
||||||
;; (defface org-item-checkbox '((t ())) "Face for checkbox list lines")
|
;; (defface org-item-checkbox '((t ())) "Face for checkbox list lines")
|
||||||
;; (defface org-item-checkbox-checked '((t ())) "Face for checked checkbox list lines")
|
;; (defface org-item-checkbox-checked '((t ())) "Face for checked checkbox list lines")
|
||||||
(defface org-whitespace '((t ())) "Face for spaces")
|
(defface org-whitespace '((t ())) "Face for spaces")
|
||||||
|
(defface org-list-bullet '((t ())) "Face for list bullets")
|
||||||
(font-lock-add-keywords
|
(font-lock-add-keywords
|
||||||
'org-mode `(("^ *\\(#\\+begin_src\\>\\)"
|
'org-mode `(("^ *\\(#\\+begin_src\\>\\)"
|
||||||
(1 (narf/show-as ?#)))
|
(1 (narf/show-as ?#)))
|
||||||
|
@ -213,10 +214,10 @@ will function properly."
|
||||||
(1 (narf/show-as ?\")))
|
(1 (narf/show-as ?\")))
|
||||||
|
|
||||||
;; Hide TODO tags
|
;; Hide TODO tags
|
||||||
("\\(\\* DONE\\) \\([^$:\n\r]+\\)"
|
("^\\**\\(\\* DONE\\) \\([^$:\n\r]+\\)"
|
||||||
(1 (narf/show-as ?☑))
|
(1 (narf/show-as ?☑))
|
||||||
(2 'org-headline-done))
|
(2 'org-headline-done))
|
||||||
("\\(\\* TODO\\) [^$:\n\r]+"
|
("^\\**\\(\\* TODO\\) "
|
||||||
(1 (narf/show-as ?☐)))
|
(1 (narf/show-as ?☐)))
|
||||||
|
|
||||||
("[-+*] \\(\\[ \\]\\) "
|
("[-+*] \\(\\[ \\]\\) "
|
||||||
|
@ -225,18 +226,11 @@ will function properly."
|
||||||
(1 (narf/show-as ?☑))
|
(1 (narf/show-as ?☑))
|
||||||
(2 'org-headline-done))
|
(2 'org-headline-done))
|
||||||
|
|
||||||
;; ("\\([-+] \\(\\[ \\]\\) \\([^$:\n\r]+\\)\\)"
|
|
||||||
;; (2 'org-item-checkbox))
|
|
||||||
;; ("\\([-+] \\(\\[X\\]\\) \\([^$:\n\r]+\\)\\)"
|
|
||||||
;; (2 'org-item-checkbox-checked))
|
|
||||||
|
|
||||||
;; Color code TODOs with !'s to denote priority
|
;; Color code TODOs with !'s to denote priority
|
||||||
("\\* TODO\\( !\\)! [^$:\n\r]+"
|
("\\* TODO .* !!$"
|
||||||
(0 'org-todo-vhigh)
|
(0 'org-todo-vhigh))
|
||||||
(1 (narf/show-as ?!)))
|
("\\* TODO .* !$"
|
||||||
("\\* TODO\\( !\\) [^$:\n\r]+"
|
(0 'org-todo-high))
|
||||||
(0 'org-todo-high)
|
|
||||||
(1 (narf/show-as ?!)))
|
|
||||||
|
|
||||||
;; Show checkbox for other todo states (but don't hide the label)
|
;; Show checkbox for other todo states (but don't hide the label)
|
||||||
(,(concat
|
(,(concat
|
||||||
|
@ -245,14 +239,12 @@ will function properly."
|
||||||
" ")
|
" ")
|
||||||
(1 (narf/show-as ?☐)))
|
(1 (narf/show-as ?☐)))
|
||||||
|
|
||||||
("^ *\\([-+]\\)\\( \\)+[^$\n\r]+"
|
("^ *\\([-+]\\|[0-9]+[).]\\)\\( \\)+[^$\n\r]+"
|
||||||
(1 'org-code)
|
(1 'org-list-bullet))
|
||||||
;; (2 'org-whitespace)
|
|
||||||
)
|
|
||||||
("^ +\\(\\*\\) "
|
("^ +\\(\\*\\) "
|
||||||
(1 (narf/show-as ?◦)))
|
(1 (narf/show-as ?◦)))
|
||||||
;; ("^ +"
|
("^ +"
|
||||||
;; (0 'org-whitespace))
|
(0 'org-whitespace))
|
||||||
)))
|
)))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -261,17 +253,14 @@ will function properly."
|
||||||
(evil-org-mode +1)
|
(evil-org-mode +1)
|
||||||
(org-bullets-mode +1)
|
(org-bullets-mode +1)
|
||||||
(org-indent-mode +1)
|
(org-indent-mode +1)
|
||||||
;; (text-scale-set 0.5)
|
(text-scale-set 1)
|
||||||
|
|
||||||
(diminish 'org-indent-mode)
|
(diminish 'org-indent-mode)
|
||||||
|
|
||||||
(narf|enable-tab-width-2)
|
(narf|enable-tab-width-2)
|
||||||
(setq truncate-lines nil)
|
(setq truncate-lines nil)
|
||||||
(setq line-spacing '0.2)
|
(setq line-spacing '0.2)
|
||||||
;; (variable-pitch-mode 1)
|
(variable-pitch-mode 1)
|
||||||
|
|
||||||
;; Allow cursor beyond eol so we can reach around hidden emphasis markers
|
|
||||||
(set (make-local-variable 'evil-move-beyond-eol) t)
|
|
||||||
|
|
||||||
(defun narf|org-update-statistics-cookies () (org-update-statistics-cookies t))
|
(defun narf|org-update-statistics-cookies () (org-update-statistics-cookies t))
|
||||||
(add-hook 'before-save-hook 'narf|org-update-statistics-cookies nil t)
|
(add-hook 'before-save-hook 'narf|org-update-statistics-cookies nil t)
|
||||||
|
@ -313,6 +302,28 @@ will function properly."
|
||||||
(org-add-link-type "project" 'narf/org-link-project)
|
(org-add-link-type "project" 'narf/org-link-project)
|
||||||
(org-add-link-type "invoice" 'narf/org-link-invoice)
|
(org-add-link-type "invoice" 'narf/org-link-invoice)
|
||||||
|
|
||||||
|
(add-to-list 'recentf-exclude (expand-file-name "%s.+\\.org$" org-directory))
|
||||||
|
(after! helm
|
||||||
|
(mapc (lambda (r) (add-to-list 'helm-boring-file-regexp-list r))
|
||||||
|
(list "\\.attach$" "\\.Rhistory$")))
|
||||||
|
|
||||||
|
(after! winner
|
||||||
|
(dolist (bufname '("*Org todo*"
|
||||||
|
"*Org Links*"
|
||||||
|
"*Agenda Commands*"))
|
||||||
|
(push bufname winner-boring-buffers)))
|
||||||
|
|
||||||
|
;; fix some org-mode + yasnippet conflicts:
|
||||||
|
(defun yas/org-very-safe-expand ()
|
||||||
|
(let ((yas/fallback-behavior 'return-nil)) (yas/expand)))
|
||||||
|
|
||||||
|
(add-hook 'org-mode-hook
|
||||||
|
(lambda ()
|
||||||
|
(make-variable-buffer-local 'yas/trigger-key)
|
||||||
|
(setq yas/trigger-key [tab])
|
||||||
|
(add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
|
||||||
|
(define-key yas/keymap [tab] 'yas-next-field)))
|
||||||
|
|
||||||
;;; Evil integration
|
;;; Evil integration
|
||||||
(progn
|
(progn
|
||||||
(advice-add 'evil-force-normal-state :before 'org-remove-occur-highlights)
|
(advice-add 'evil-force-normal-state :before 'org-remove-occur-highlights)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue