The ciiiircle of liiiife

This commit is contained in:
Henrik Lissner 2015-11-25 06:00:49 -05:00
parent 0923903e93
commit 03c6c05677
29 changed files with 287 additions and 465 deletions

View file

@ -1,145 +0,0 @@
;;; defuns-org-custom.el -- custom functions, links, etc. for Org-mode
;;; 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))
;;;###autoload
(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))
;;;###autoload
(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 org-contact-complete-link ()
(narf/org-complete "contact"))
;;;###autoload
(defun org-project-complete-link ()
(narf/org-complete "project"))
;;;###autoload
(defun org-invoice-complete-link ()
(narf/org-complete "invoice"))
;;; 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)
(let ((narf--helm-org-dir org-directory-projects))
(narf--helm-org)))
;;;###autoload
(defun narf/helm-org-contacts ()
(interactive)
(let ((narf--helm-org-dir org-directory-contacts))
(narf--helm-org)))
;;;###autoload
(defun narf/helm-org-invoices ()
(interactive)
(let ((narf--helm-org-dir org-directory-invoices))
(narf--helm-org)))
;;;###autoload
(defun narf/helm-org-writing ()
(interactive)
(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

@ -113,39 +113,6 @@
(defun narf/org-surround (delim)
(insert delim) (save-excursion (insert delim)))
;;;###autoload (autoload 'narf:org-search-files-or-headers "defuns-org" nil t)
(evil-define-command narf:org-search-files-or-headers (&optional bang)
(interactive "<!>")
(require 'org)
(if bang
(ido-find-file-in-dir org-directory)
(call-interactively 'helm-org-agenda-files-headings)))
;;;###autoload
(defun narf:org-list-attachments ()
"Find files in org-attachment directory"
(interactive)
(let* ((enable-recursive-minibuffers t)
(files (find-lisp-find-files org-attach-directory "."))
(file-assoc-list
(mapcar (lambda (x)
(cons (file-name-nondirectory x)
x))
files))
(filename-list
(remove-duplicates (mapcar #'car file-assoc-list)
:test #'string=))
(filename (ido-completing-read "Org attachments: " filename-list nil t))
(longname (cdr (assoc filename file-assoc-list))))
(ido-set-current-directory
(if (file-directory-p longname)
longname
(file-name-directory longname)))
(setq ido-exit 'refresh
ido-text-init ido-text
ido-rotate-temp t)
(exit-minibuffer)))
;;;###autoload
(defun narf/org-word-count (beg end &optional count-footnotes?)
"Report the number of words in the Org mode buffer or selected region.
@ -218,22 +185,6 @@ COUNT-FOOTNOTES? is non-nil."
(message (format "%d words in %s." wc
(if mark-active "region" "buffer")))))
;;;###autoload (autoload 'narf:org-attach "defuns-org" nil t)
(evil-define-command narf:org-attach (&optional link)
(interactive "<a>")
(require 'org-attach)
(let ((path ".attach")
(new-name (concat (int-to-string (truncate (float-time))) "-" (f-filename link)))
new-path)
(unless (file-exists-p path)
(make-directory path))
(when path
(setq new-path (format "%s/%s" path new-name))
(cond ((string-match-p "^https?://" link)
(url-copy-file link new-path))
(t (copy-file link new-path)))
(insert (format "[[./%s]]" (abbreviate-file-name new-path))))))
;;;###autoload (autoload 'narf:org-export "defuns-org" nil t)
(evil-define-command narf:org-export (dest)
(interactive "<a>")
@ -324,16 +275,14 @@ re-align the table if necessary. (Necessary because org-mode has a
(when (org-looking-at-p " ") (forward-char))))
;;;###autoload
(defun narf/org-replace-link-by-link-description ()
"Replace an org link by its description or if empty its address"
(interactive)
(if (org-in-regexp org-bracket-link-regexp 1)
(let ((remove (list (match-beginning 0) (match-end 0)))
(description (if (match-end 3)
(org-match-string-no-properties 3)
(org-match-string-no-properties 1))))
(apply 'delete-region remove)
(insert description))))
(defun narf/-org-capture-changelog ()
;; TODO
)
;;;###autoload
(defun narf/-org-capture-choose ()
;; TODO
)
(provide 'defuns-org)
;;; defuns-org.el ends here

View file

@ -106,5 +106,7 @@
coffee-tab-width 2
coffee-indent-like-python-mode t))
(use-package nodejs-repl :defer t)
(provide 'module-js)
;;; module-js.el ends here

View file

@ -40,6 +40,7 @@
org-footnote-auto-label 'plain
org-log-done t
org-agenda-window-setup 'other-window
org-agenda-skip-unavailable-files t
org-src-window-setup 'current-window
org-startup-folded 'content
org-todo-keywords '((sequence "TODO(t)" "|" "DONE(d)")
@ -141,7 +142,7 @@
'org-babel-load-languages
'((python . t) (ruby . t) (sh . t) (js . t) (css . t)
(plantuml . t) (emacs-lisp . t) (matlab . t)
(latex . t) (calc . t)
(latex . t) (calc . t) (lisp . t)
(http . t) (rust . t) (go . t)))
(setq org-plantuml-jar-path puml-plantuml-jar-path)
@ -272,7 +273,10 @@ will function properly."
(setq line-spacing '0.2)
(variable-pitch-mode 1)
(defun narf|org-update-statistics-cookies () (org-update-statistics-cookies t))
(defun narf|org-update-statistics-cookies ()
(when (file-exists-p buffer-file-name)
(org-update-statistics-cookies t)))
(add-hook 'before-save-hook 'narf|org-update-statistics-cookies nil t)
(add-hook 'evil-insert-state-exit-hook 'narf|org-update-statistics-cookies nil t)
@ -308,9 +312,9 @@ will function properly."
(add-hook 'org-mode-hook 'narf|org-hook)
(org-add-link-type "contact" 'narf/org-link-contact)
(org-add-link-type "project" 'narf/org-link-project)
(org-add-link-type "invoice" 'narf/org-link-invoice)
(org-add-link-type "contact" 'narf/org-crm-link-contact)
(org-add-link-type "project" 'narf/org-crm-link-project)
(org-add-link-type "invoice" 'narf/org-crm-link-invoice)
(add-to-list 'recentf-exclude (expand-file-name "%s.+\\.org$" org-directory))
(after! helm
@ -346,18 +350,17 @@ will function properly."
(define-text-object! "=" "=" "=")
(define-text-object! "~" "~" "~"))
;;; File templates
(after! autoinsert
(add-template! (format "%s.+\\.org$" org-directory-contacts) "__contact.org" 'org-mode)
(add-template! (format "%s.+\\.org$" org-directory-projects) "__projects.org" 'org-mode)
(add-template! (format "%s.+\\.org$" org-directory-invoices) "__invoices.org" 'org-mode))
;;; Plugins
(require 'org-download)
(setq-default
org-download-image-dir ".attach/"
org-download-image-dir ".attach"
org-download-heading-lvl nil
org-download-timestamp "_%Y%m%d_%H%M%S"
org-download-screenshot-method "screencapture -i %s")
(defun org-download--dir-2 ()
(f-base (buffer-file-name)))
;;; Auto-completion
(after! company
(require 'company-math)
@ -426,8 +429,7 @@ will function properly."
:n ",f" 'org-sparse-tree
:n ",?" 'org-tags-view
:n ",e" 'org-edit-special
:n ",a" 'org-attach
:n ",A" 'org-agenda
:n ",a" 'org-agenda
:n ",D" 'org-time-stamp-inactive
:n ",i" 'narf/org-toggle-inline-images-at-point
:n ",t" 'org-todo
@ -435,6 +437,7 @@ will function properly."
:n ",d" 'org-time-stamp
:n ",r" 'org-refile
:n ",s" 'org-schedule
:n ",oa" 'narf/org-reveal-attachments
:n ", SPC" 'narf/org-toggle-checkbox
:n ", RET" 'org-archive-subtree
@ -462,7 +465,7 @@ will function properly."
:n "go" 'org-open-at-point
:n "gO" (λ (let ((org-link-frame-setup (append '((file . find-file-other-window)) org-link-frame-setup))
(org-file-apps '(("\\.org$" . emacs)
(t . "qlmanage -p \"%s\""))))
(t . "open \"%s\""))))
(call-interactively 'org-open-at-point)))
:n "gQ" 'org-fill-paragraph

View file

@ -24,6 +24,8 @@
(require 'php-refactor-mode)
(add-hook! php-mode '(turn-on-eldoc-mode emr-initialize php-refactor-mode)))
(use-package php-boris :defer t)
(use-package hack-mode :mode "\\.hh$")
(provide 'module-php)