Improve org integration

This commit is contained in:
Henrik Lissner 2015-11-23 15:21:24 -05:00
parent 1b67819fc7
commit 060f9cd9b1
6 changed files with 146 additions and 65 deletions

View file

@ -188,6 +188,8 @@ enable multiple minor modes for the same regexp.")
(sp-local-pair "/*\n" "\n */" :post-handlers '(("||[i]" "RET"))))
(sp-with-modes '(c-mode c++-mode php-mode java-mode)
(sp-local-pair "/*" "" :post-handlers '((" ||\n[i]*/" "RET"))))
(sp-with-modes '(org-mode)
(sp-local-pair "{" nil))
(after! yasnippet
(advice-add 'yas-expand :before 'sp-remove-active-pair-overlay))

View file

@ -17,9 +17,9 @@
("*Flycheck errors*" :position bottom :height 15 :stick t)
("^\\*[Hh]elm.*?\\*\\'" :regexp t :position bottom :height 0.2)
("^\\*Org-Babel.*\\*$" :regexp t :position bottom :height 15 :tail t)
;; ("^\\*Org .*\\*$" :regexp t :position bottom :height 15 :stick t)
;; ("^\\*org .*\\*$" :regexp t :position bottom :height 15 :stick t)
("*Agenda Commands*" :position bottom :height 0.5)
("*Org todo*" :position bottom :height 5)
(" *Org todo*" :position bottom :height 5)
("*Org Links*" :position bottom :height 2)
("^\\*CPU-Profiler-Report .+\\*$" :regexp t :position bottom :height 0.35)
))
@ -125,7 +125,8 @@
(defun org-switch-to-buffer-other-window (&rest args)
(mapc (lambda (b)
(popwin:popup-buffer (if (bufferp b) b (get-buffer-create b)) :height 0.5))
(let ((buf (if (stringp b) (get-buffer-create b) b)))
(popwin:pop-to-buffer buf t t)))
args)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -90,19 +90,5 @@
(interactive "<a><!>")
(if bang (helm-multi-swoop-all search) (helm-swoop :$query search)))
;;;###autoload
(defun narf/helm-org-search (&optional directory)
(interactive)
(require 'helm-ag)
(require 'helm-deft)
(let ((dir (or directory org-directory)))
(let ((helm-deft-dir-list `(,dir))
(default-directory dir)
(helm-ag--default-directory dir))
(helm :sources `(,(if directory
'helm-source-deft-fn
'helm-source-projectile-files-list)
helm-source-do-ag)))))
(provide 'defuns-helm)
;;; defuns-helm.el ends here

View file

@ -37,23 +37,109 @@
(defun org-invoice-complete-link ()
(narf/org-complete "invoice"))
;;; Deft
;;; Personal CRM
;; (defvar narf--helm-org-cache '())
(defvar narf--helm-org-files '())
(defun narf--helm-org-init ()
(setq narf--helm-org-files
(mapcar 'narf--helm-org-metadata
(f-entries narf--helm-org-dir (lambda (f) (and (f-ext? f "org") (> (f-size f) 0))) t))))
(defun narf--helm-org-metadata (file &optional params)
(let ((params (or params narf--helm-org-params))
(base (f-base file))
alist content title)
(with-temp-buffer
(insert-file-contents file nil nil nil t)
(setq content (concat (buffer-string))))
(setq title (let ((title (deft-parse-title file content)))
(if (string= title "")
"-"
title)))
(setq alist
(list file
(cons 'id (substring base 0 (string-match "-" base)))
(cons 'path file)
(cons 'title title)
(cons 'summary (truncate-string-to-width
(replace-regexp-in-string
"[\n\t]" " "
(if title
(if (string-match (regexp-quote "#+end_src") content)
(deft-chomp (substring content (match-end 0)
(string-match "^\\* " content (match-end 0))))
"")
content)
content)
(window-width)))))
(mapc (lambda (p)
(let ((value (if (string-match (concat "^" (symbol-name p) ": +\\(.*\\)$") content)
(substring content (match-beginning 1) (match-end 1)))))
(when value
(add-to-list 'alist (cons p value) t))))
params)
alist))
(defvar narf--helm-org-title "Org files")
(defvar narf--helm-org-dir org-directory)
(defvar narf--helm-org-params '(created contact email country issued paid))
(defun narf/helm-org-candidates ()
narf--helm-org-files)
(defun narf/helm-org-real-to-display (alist)
(format "[%s] [%s] %-20s -- (%s) %s"
(cdr-safe (assoc 'id alist))
(cdr-safe (assoc 'created alist))
(cdr-safe (assoc 'title alist))
(or (cdr-safe (assoc 'contact alist))
(cdr-safe (assoc 'email alist))
(cdr-safe (assoc 'country alist))
"")
(cdr-safe (assoc 'summary alist))))
(defun narf/helm-org-action (alist)
(find-file (cdr-safe (assoc 'path alist))))
(defun narf--helm-org ()
(require 'deft)
(helm :sources (helm-build-sync-source narf--helm-org-title
:init 'narf--helm-org-init
:candidates 'narf/helm-org-candidates
:real-to-display 'narf/helm-org-real-to-display
:action 'narf/helm-org-action)
:buffer "*helm-deft*"))
;;;###autoload
(defun narf/helm-org-index ()
(interactive)
(let ((narf--helm-org-dir org-directory)
(narf--helm-org-params '()))
(narf--helm-org)))
;;;###autoload
(defun narf/helm-org-projects ()
(interactive)
(narf/helm-org-search org-directory-projects))
(let ((narf--helm-org-dir org-directory-projects))
(narf--helm-org)))
;;;###autoload
(defun narf/helm-org-contacts ()
(interactive)
(narf/helm-org-search org-directory-contacts))
(let ((narf--helm-org-dir org-directory-contacts))
(narf--helm-org)))
;;;###autoload
(defun narf/helm-org-invoices ()
(interactive)
(narf/helm-org-search org-directory-invoices))
(let ((narf--helm-org-dir org-directory-invoices))
(narf--helm-org)))
;;;###autoload
(defun narf/helm-org-writing ()
(interactive)
(narf/helm-org-search (expand-file-name "writing/" org-directory)))
(let ((narf--helm-org-dir (expand-file-name "writing/" org-directory))
(narf--helm-org-params '()))
(narf--helm-org)))
(provide 'defuns-org-custom)
;;; defuns-org-custom.el ends here

View file

@ -27,6 +27,7 @@
;; org-mobile-inbox-for-pull (concat org-directory "inbox.org")
;; org-mobile-directory "~/Dropbox/Apps/MobileOrg"
org-default-priority ?C
org-catch-invisible-edits nil
org-confirm-elisp-link-function nil
org-completion-use-ido t
@ -116,27 +117,30 @@
org-src-tab-acts-natively t)
(defun narf-refresh-babel-lob ()
(async-start
`(lambda ()
,(async-inject-variables "\\`\\(org-directory\\|load-path$\\)")
(require 'org)
(require 'f)
(setq org-babel-library-of-babel nil)
(mapc (lambda (f) (org-babel-lob-ingest f))
(f-entries ,org-directory (lambda (path) (f-ext? path "org")) t))
org-babel-library-of-babel)
(lambda (lib)
;; (persistent-soft-store 'org-babel-library lib "org")
(message "Library of babel updated!")
(setq org-babel-library-of-babel lib))))
(let ((files (f-entries org-directory (lambda (path) (f-ext? path "org")) t)))
(async-start
`(lambda ()
,(async-inject-variables "\\`\\(org-directory\\|load-path$\\)")
(require 'org)
(setq org-babel-library-of-babel nil)
(mapc (lambda (f) (org-babel-lob-ingest f)) (list ,@files))
org-babel-library-of-babel)
(lambda (lib)
;; (persistent-soft-store 'org-babel-library lib "org")
(message "Library of babel updated!")
(setq org-babel-library-of-babel lib)))))
(setq org-babel-library-of-babel (narf-refresh-babel-lob))
(add-hook! org-mode
(add-hook 'after-save-hook (lambda () (shut-up! (org-babel-lob-ingest (buffer-file-name)))) t t))
(add-hook 'after-save-hook
(lambda ()
(when (file-exists-p buffer-file-name)
(shut-up! (org-babel-lob-ingest buffer-file-name))))
t t))
(org-babel-do-load-languages
'org-babel-load-languages
'((python . t) (ruby . t) (sh . t) (js . t) (css . t)
(plantuml . t) (emacs-lisp . t) (matlab . t) (R . t)
(plantuml . t) (emacs-lisp . t) (matlab . t)
(latex . t) (calc . t)
(http . t) (rust . t) (go . t)))
@ -180,7 +184,12 @@ will function properly."
org-cycle-separator-lines 2
org-hide-emphasis-markers t
org-hide-leading-stars t
org-bullets-bullet-list '("" "" "" "" "" "" ""))
org-bullets-bullet-list '("" "" "" "" "" "" "")
org-priority-faces
'((?A . org-todo-vhigh)
(?B . org-todo-high)))
;; Restore org-block-background face (removed in official org)
(defface org-block-background '((t ()))
@ -197,6 +206,7 @@ will function properly."
(face-attribute 'org-block-background :inherit)))
;; Prettify symbols, blocks and TODOs
(defface org-headline-todo '((t ())) "Face for todo headlines")
(defface org-todo-high '((t ())) "Face for high-priority todo")
(defface org-todo-vhigh '((t ())) "Face for very high-priority todo")
;; (defface org-item-checkbox '((t ())) "Face for checkbox list lines")
@ -214,24 +224,24 @@ will function properly."
(1 (narf/show-as ?\")))
;; Hide TODO tags
("^\\**\\(\\* DONE\\) \\([^$:\n\r]+\\)"
("^\\**\\(\\* DONE\\) \\([^$\n\r]+\\)"
(1 (narf/show-as ?☑))
(2 'org-headline-done))
("^\\**\\(\\* TODO\\) "
("^\\**\\(\\* TODO\\) \\([^$\n\r]+\\)?"
(1 (narf/show-as ?☐)))
;; Unbold-ify todos
(,(concat "^\\**\\(\\* "
(regexp-opt '("TODO" "LEAD" "NEXT" "ACTIVE" "PENDING" "CANCELLED"))
"\\)\\( [^$\n\r]*\\)?")
(2 'org-headline-todo))
("[-+*] \\(\\[ \\]\\) "
(1 (narf/show-as ?☐)))
("[-+*] \\(\\[X\\]\\) \\([^$:\n\r]+\\)"
("[-+*] \\(\\[X\\]\\) \\([^$\n\r]+\\)"
(1 (narf/show-as ?☑))
(2 'org-headline-done))
;; Color code TODOs with !'s to denote priority
("\\* TODO .* !!$"
(0 'org-todo-vhigh))
("\\* TODO .* !$"
(0 'org-todo-high))
;; Show checkbox for other todo states (but don't hide the label)
(,(concat
"\\(\\*\\) "
@ -344,25 +354,21 @@ will function properly."
;;; Plugins
(require 'org-download)
(setq org-download-image-dir ".attach/"
org-download-screenshot-method "screencapture -i %s")
(use-package deft :defer t
:config
(setq deft-directory org-directory
deft-recursive t
deft-separator " :: "))
(setq-default
org-download-image-dir ".attach/"
org-download-screenshot-method "screencapture -i %s")
;;; Auto-completion
(require 'company-math)
(define-company-backend! org-mode
(math-symbols-latex
math-symbols-unicode
latex-commands
capf
yasnippet
dabbrev-code
keywords))
(after! company
(require 'company-math)
(define-company-backend! org-mode
(math-symbols-latex
math-symbols-unicode
latex-commands
capf
yasnippet
dabbrev-code
keywords)))
(define-key org-mode-map (kbd "RET") nil)
(define-key org-mode-map (kbd "C-j") nil)

View file

@ -145,7 +145,7 @@
;; Org
:nv "n." (λ (in! org-directory (let ((helm-ff-skip-boring-files t)) (helm-find-files-1 org-directory))))
:nv "n/" 'narf/helm-org-search
:nv "n/" 'narf/helm-org-index
:nv "np" 'narf/helm-org-projects
:nv "nc" 'narf/helm-org-contacts
:nv "ni" 'narf/helm-org-invoices