Refactor org-mode config

This commit is contained in:
Henrik Lissner 2015-11-21 18:03:11 -05:00
parent 8537361e50
commit b7d03fff52
3 changed files with 104 additions and 98 deletions

View file

@ -1,57 +1,61 @@
;;; defuns-org-custom.el -- custom functions, links, etc. for Org-mode
(progn ;; Custom links
(defun narf--org-id-to-file (id dir &optional pattern)
(let* ((glob (f-glob (format (concat "%s" (or pattern "%s-*.org")) dir id)))
(glob-len (length glob)))
(when (zerop glob-len)
(user-error "Could not find file with that ID"))
(car glob)))
;;; Custom links
(defun narf--org-id-to-file (id dir &optional pattern)
(let* ((glob (f-glob (format (concat "%s" (or pattern "%s-*.org")) dir id)))
(glob-len (length glob)))
(when (zerop glob-len)
(user-error "Could not find file with that ID"))
(car glob)))
;;;###autoload
(defun narf/org-link-contact (id)
(org-open-file (narf--org-id-to-file id org-directory-contacts) t))
(defun narf/org-link-contact (id)
(org-open-file (narf--org-id-to-file id org-directory-contacts) t))
;;;###autoload
(defun narf/org-link-project (id)
(org-open-file (narf--org-id-to-file id org-directory-projects) t))
(defun narf/org-link-project (id)
(org-open-file (narf--org-id-to-file id org-directory-projects) t))
;;;###autoload
(defun narf/org-link-invoice (id)
(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)))
(defun narf/org-link-invoice (id)
(org-open-file (narf--org-id-to-file id org-directory-invoices "%s.org") t))
;;;###autoload
(defun narf/deft-contact ()
(interactive)
(require 'deft)
(let ((deft-directory org-directory-contacts))
(deft)))
(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)))))
;;;###autoload
(defun narf/deft-invoices ())
(defun org-contact-complete-link ()
(narf/org-complete "contact"))
;;;###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)
;;; defuns-org-custom.el ends here

View file

@ -27,24 +27,14 @@
('above
(narf/org-table-prepend-row-or-shift-up))))
(t
(org-back-to-heading)
(let ((first-p (org-first-sibling-p))
(orig-char (point)))
(cl-case direction
('below
(org-insert-heading-after-current)
(unless first-p
(save-excursion
(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))))))))
(cl-case direction
('below
(org-insert-heading-after-current))
('above
(org-back-to-heading)
(org-insert-heading)))
(when (org-element-property :todo-type context)
(org-todo 'todo))))
(evil-append-line 1)))
;;;###autoload
@ -250,10 +240,11 @@ COUNT-FOOTNOTES? is non-nil."
(let ((path (if (string-match-p "^[/~]" dest)
dest
(expand-file-name dest default-directory))))
(shell-command
(format "/usr/local/bin/pandoc '%s' -o '%s'"
(buffer-file-name) path))
(message "Done! Exported to: %s" path)))
(if (shell-command
(format "/usr/local/bin/pandoc '%s' -o '%s'"
(buffer-file-name) path))
(message "Done! Exported to: %s" path)
(user-error "Export failed"))))
;;;###autoload
(defun narf/org-remove-link ()