Remove org-mode config (I no longer use org-mode)

This commit is contained in:
Henrik Lissner 2016-02-26 00:02:37 -05:00
parent 8d09932cc6
commit fea2a2ce4a
10 changed files with 0 additions and 1382 deletions

View file

@ -1,86 +0,0 @@
;;; defuns-org-attach.el --- custom attachment system
;; I know Org has its own attachment system, but I don't like it.
;;;###autoload (autoload 'narf:org-attach "defuns-org-attach" nil t)
(evil-define-command narf:org-attach (&optional bang link)
(interactive "<!><a>")
(if (not link)
(narf:org-attachment-list bang)
(require 'org-download)
(let ((new-path (if bang
(format "%s/%s" (expand-file-name org-download-image-dir org-directory)
(format "%s%s.%s"
(f-base link)
(format-time-string org-download-timestamp)
(file-name-extension link))) buffer-file-name
(org-download--fullname link))))
(unless new-path
(user-error "No file was provided"))
(cond ((string-match-p "^https?://" link)
(url-copy-file link new-path))
(t (copy-file link new-path)))
(let ((relpath (f-relative new-path default-directory)))
(if (evil-visual-state-p)
(org-insert-link nil (format "./%s" relpath) (buffer-substring-no-properties (region-beginning) (region-end)))
(insert (format "[[./%s]]" relpath)))))))
;;;###autoload (autoload 'narf:org-attachment-list "defuns-org-attach" nil t)
(evil-define-command narf:org-attachment-list (&optional bang)
(interactive "<!>")
(if bang
(narf:org-attachment-cleanup)
(let ((attachments (narf-org--get-attachments)))
(unless attachments
(user-error "No attachments in this file"))
(helm :sources
(helm-build-sync-source "Attachments"
:candidates attachments
:real-to-display 'narf-org--attachment-real-to-display
:action '(("Go to Attachment in Buffer" . narf-org--attachment-find)
("Reveal Attachment in Finder" . narf-org--attachment-reveal)
("Open Attachment" . narf-org--attachment-open)
("Delete Attachment" . narf-org--attachment-delete)))))))
;; TODO Improve
;;;###autoload
(defun narf/org-attachment-reveal ()
(interactive)
(let ((context (org-element-context)))
(narf-open-with
nil
(if (and context (eq (org-element-type context) 'link))
(f-dirname (org-element-property :path context))
org-download-image-dir))))
(defun narf-org--get-attachments ()
(org-element-map (org-element-parse-buffer) 'link
(lambda (link)
(when (and (string= (org-element-property :type link) "file")
(string-prefix-p (format "./%s" org-download-image-dir)
(org-element-property :path link)))
(org-element-property :path link)))))
(defun narf-org--attachment-real-to-display (real)
(propertize (f-filename real) 'face (if (file-exists-p real) 'helm-ff-file 'shadow)))
(defun narf-org--attachment-find (file)
(search-forward-regexp (format "[[\\(file:\\)?%s]]" file) nil t)
(ignore-errors
(save-excursion
(outline-previous-visible-heading 1)
(org-show-subtree))))
(defun narf-org--attachment-reveal (file)
(narf-open-with nil (f-dirname file)))
(defun narf-org--attachment-open (file)
(narf-open-with nil file))
(defun narf-org--attachment-delete (file)
(delete-file file)
(narf-org--attachment-find file)
(message "File deleted, now delete the link! (%s)" file))
(provide 'defuns-org-attach)
;;; defuns-org-attach.el ends here

View file

@ -1,115 +0,0 @@
;;; defuns-org-crm.el --- for my custom org-based CRM
(require 'helm-deft)
(defun narf--helm-org (&optional directory)
(let ((helm-deft-dir-list `(,(or directory default-directory))))
(helm-deft)))
;;;###autoload
(defun narf/helm-org ()
(interactive)
(narf--helm-org org-directory))
;;;###autoload
(defun narf/helm-org-crm-projects ()
(interactive)
(narf--helm-org org-directory-projects))
;;;###autoload
(defun narf/helm-org-crm-contacts ()
(interactive)
(narf--helm-org org-directory-contacts))
;;;###autoload
(defun narf/helm-org-crm-invoices ()
(interactive)
(narf--helm-org org-directory-invoices))
;;;###autoload
(defun narf/helm-org-writing ()
(interactive)
(let ((narf--helm-org-params '()))
(narf--helm-org (expand-file-name "writing/" org-directory))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun narf--org-crm-assert-type (type)
(unless (memq type '(project contact invoice))
(user-error "Not a valid type: %s" type)))
(defun narf--org-crm-new-path (name type)
(narf--org-crm-assert-type type)
(let* ((prefix
(replace-regexp-in-string
"/+$" "" (symbol-value (intern (format "org-directory-%ss" type)))))
(last-file (car-safe (sort (f-glob "*.org" prefix) 'org-string>))))
(when last-file
(let* ((old-id (narf--org-crm-path-to-id last-file type))
(new-id (format "%04X" (1+ old-id))))
(if (eq type 'invoice)
(format "%s/%s-%s.org" prefix (format-time-string "%y%m") new-id)
(format "%s/%s-%s.org" prefix
new-id (replace-regexp-in-string "[][ !@#$%^&*()]" "-" name)))))))
(defun narf--org-crm-path-to-id (path type)
(narf--org-crm-assert-type type)
(let ((base (f-filename path)))
(string-to-number
(if (eq type 'invoice)
(substring base (1+ (string-match-p "-" base)) (string-match-p ".org" base))
(substring base 0 (string-match-p "[-.]" base)))
16)))
(defun narf--org-crm-id-to-path (id type)
(narf--org-crm-assert-type type)
(let* ((prefix
(replace-regexp-in-string
"/+$" "" (symbol-value (intern (format "org-directory-%ss" type))))))
(car-safe
(f-glob (format (cond ((eq type 'invoice)
"*-%04X.org")
((eq type 'courses)
"%s*.org")
(t
"%04X*.org"))
(string-to-number id 16))
prefix))))
(defun narf--org-crm (&optional id type new-p)
(let ((file (if new-p
(or (narf--org-crm-new-path id type)
(user-error "path could not be resolved: type(%s) name(%s)" type name))
(or (narf--org-crm-id-to-path id type)
(user-error "id %s could not be resolved in %s" id type))))
(old-buffer (current-buffer)))
(find-file file)
(with-current-buffer old-buffer
(when (evil-visual-state-p)
(org-insert-link
nil (format "%s:%s" (symbol-name type) (narf--org-crm-path-to-id file type))
(buffer-substring-no-properties (region-beginning) (region-end)))))))
;;;###autoload (autoload 'narf:org-crm-project "defuns-org-crm" nil t)
(evil-define-command narf:org-crm-project (&optional bang name)
(interactive "<!><a>")
(if bang
(narf--org-crm name 'project t)
(narf/helm-org-crm-projects)))
;;;###autoload (autoload 'narf:org-crm-contact "defuns-org-crm" nil t)
(evil-define-command narf:org-crm-contact (&optional bang name)
(interactive "<!><a>")
(if bang
(narf--org-crm name 'contact t)
(narf/helm-org-crm-contacts)))
;;;###autoload (autoload 'narf:org-crm-invoice "defuns-org-crm" nil t)
(evil-define-command narf:org-crm-invoice (&optional bang)
(interactive "<!>")
(if bang
(narf--org-crm nil 'invoice t)
(narf/helm-org-crm-invoices)))
(provide 'defuns-org-crm)
;;; defuns-org-crm.el ends here

View file

@ -1,306 +0,0 @@
;;; defuns-org.el
;;;###autoload
(defun narf/org-get-property (name)
(interactive)
(save-excursion
(goto-char 1)
(re-search-forward (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase name)) nil t)
(buffer-substring-no-properties (match-beginning 1) (match-end 1))))
;;;###autoload
(defun narf/org-open-notes ()
(interactive)
(find-file org-default-notes-file))
;;;###autoload
(defun narf/org-open-todo ()
(interactive)
(find-file org-default-todo-file))
;;;###autoload
(defun narf/org-insert-item (direction)
"Inserts a new heading or item, depending on the context."
(interactive)
(let* ((context (org-element-context)
;; (org-element-lineage
;; '(table table-row headline inlinetask
;; item plain-list)
;; t)
)
(type (org-element-type context)))
(cond ((eq type 'item)
(cl-case direction
('below
(org-end-of-line)
(org-insert-heading))
('above
(evil-first-non-blank)
(org-insert-heading)))
(when (org-element-property :checkbox context)
(insert "[ ] ")))
((memq type '(table table-row))
(cl-case direction
('below
(org-table-insert-row))
('above
(narf/org-table-prepend-row-or-shift-up))))
(t
(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
(defun narf/org-toggle-checkbox ()
(interactive)
(let ((context (org-element-lineage (org-element-context) '(item) t)))
(when context
(org-end-of-line)
(org-beginning-of-line)
(if (org-element-property :checkbox context)
(when (search-backward-regexp "\\[[ +-]\\]" (line-beginning-position) t)
(delete-char 4))
(insert "[ ] ")))))
;;;###autoload
(defun narf/org-dwim-at-point ()
(interactive)
(let* ((scroll-pt (window-start))
(context (org-element-context))
(type (org-element-type context))
(value (org-element-property :value context)))
(cond
((memq type '(table table-row))
(if (org-element-property :tblfm (org-element-property :parent context))
(org-table-recalculate t)
(org-table-align)))
((and (memq type '(item))
(org-element-property :checkbox context))
(org-toggle-checkbox))
((and (memq type '(headline))
(org-element-property :todo-type context))
(org-todo
(if (eq (org-element-property :todo-type context) 'done) 'todo 'done)))
((memq type '(headline))
(org-remove-latex-fragment-image-overlays)
(org-preview-latex-fragment '(4)))
((memq type '(babel-call))
(org-babel-lob-execute-maybe))
((memq type '(src-block inline-src-block))
(org-babel-execute-src-block))
((memq type '(latex-fragment latex-environment))
(org-preview-latex-fragment))
((memq type '(link))
(org-open-at-point))
(t (narf/org-refresh-inline-images)))
(set-window-start nil scroll-pt)))
;;;###autoload
(defun narf/org-refresh-inline-images ()
(interactive)
(if (> (length org-inline-image-overlays) 0)
(org-remove-inline-images)
(org-display-inline-images
nil t
(save-excursion (org-back-to-heading) (point))
(save-excursion (org-end-of-subtree) (point)))))
;; Formatting shortcuts
;;;###autoload
(defun narf/org-surround (delim)
(if (region-active-p)
(save-excursion
(goto-char (region-beginning))
(insert delim)
(goto-char (region-end))
(insert delim))
(insert delim)
(save-excursion (insert delim))))
;;;###autoload
(defun narf/org-word-count (beg end &optional count-footnotes?)
"Report the number of words in the Org mode buffer or selected region.
Ignores:
- comments
- tables
- source code blocks (#+BEGIN_SRC ... #+END_SRC, and inline blocks)
- hyperlinks (but does count words in hyperlink descriptions)
- tags, priorities, and TODO keywords in headers
- sections tagged as 'not for export'.
The text of footnote definitions is ignored, unless the optional argument
COUNT-FOOTNOTES? is non-nil."
(interactive "r")
(unless mark-active
(setf beg (point-min)
end (point-max)))
(let ((wc 0))
(save-excursion
(goto-char beg)
(while (< (point) end)
(cond
;; Ignore comments.
((or (org-at-comment-p) (org-at-table-p))
nil)
;; Ignore hyperlinks. But if link has a description, count
;; the words within the description.
((looking-at org-bracket-link-analytic-regexp)
(when (match-string-no-properties 5)
(let ((desc (match-string-no-properties 5)))
(save-match-data
(incf wc (length (remove "" (org-split-string
desc "\\W")))))))
(goto-char (match-end 0)))
((looking-at org-any-link-re)
(goto-char (match-end 0)))
;; Ignore source code blocks.
((org-between-regexps-p "^#\\+BEGIN_SRC\\W" "^#\\+END_SRC\\W")
nil)
;; Ignore inline source blocks, counting them as 1 word.
((save-excursion
(backward-char)
(looking-at org-babel-inline-src-block-regexp))
(goto-char (match-end 0))
(setf wc (+ 2 wc)))
;; Ignore footnotes.
((and (not count-footnotes?)
(or (org-footnote-at-definition-p)
(org-footnote-at-reference-p)))
nil)
(t
(let ((contexts (org-context)))
(cond
;; Ignore tags and TODO keywords, etc.
((or (assoc :todo-keyword contexts)
(assoc :priority contexts)
(assoc :keyword contexts)
(assoc :checkbox contexts))
nil)
;; Ignore sections marked with tags that are
;; excluded from export.
((assoc :tags contexts)
(if (intersection (org-get-tags-at) org-export-exclude-tags
:test 'equal)
(org-forward-same-level 1)
nil))
(t
(incf wc))))))
(re-search-forward "\\w+\\W*")))
(message (format "%d words in %s." wc
(if mark-active "region" "buffer")))))
;;;###autoload (autoload 'narf:org-export "defuns-org" nil t)
(evil-define-command narf:org-export (dest)
(interactive "<a>")
(let ((path (if (string-match-p "^[/~]" dest)
dest
(expand-file-name dest default-directory))))
(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 ()
"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))))
;;;###autoload
(defun narf/org-table-next-row ()
(interactive)
(if (org-at-table-p) (org-table-next-row) (org-down-element)))
;;;###autoload
(defun narf/org-table-previous-row ()
(interactive)
(if (org-at-table-p) (narf--org-table-previous-row) (org-up-element)))
;;;###autoload
(defun narf/org-table-next-field ()
(interactive)
(if (org-at-table-p) (org-table-next-field) (org-end-of-line)))
;;;###autoload
(defun narf/org-table-previous-field ()
(interactive)
(if (org-at-table-p) (org-table-previous-field) (org-beginning-of-line)))
;;;###autoload
(defun narf/org-table-append-field-or-shift-right ()
(interactive)
(org-shiftmetaright)
(when (org-at-table-p) (org-metaright)))
;;;###autoload
(defun narf/org-table-prepend-field-or-shift-left ()
(interactive)
(if (org-at-table-p)
(org-shiftmetaright)
(org-shiftmetaleft)))
;;;###autoload
(defun narf/org-table-append-row-or-shift-down ()
(interactive)
(org-shiftmetadown)
(when (org-at-table-p) (org-metadown)))
;;;###autoload
(defun narf/org-table-prepend-row-or-shift-up ()
(interactive)
(if (org-at-table-p)
(org-shiftmetadown)
(org-shiftmetaup)))
(defun narf--org-table-previous-row ()
"Go to the previous row (same column) in the current table. Before doing so,
re-align the table if necessary. (Necessary because org-mode has a
`org-table-next-row', but not `org-table-previous-row')"
(interactive)
(org-table-maybe-eval-formula)
(org-table-maybe-recalculate-line)
(if (and org-table-automatic-realign
org-table-may-need-update)
(org-table-align))
(let ((col (org-table-current-column)))
(beginning-of-line 0)
(when (or (not (org-at-table-p)) (org-at-table-hline-p))
(beginning-of-line))
(org-table-goto-column col)
(skip-chars-backward "^|\n\r")
(when (org-looking-at-p " ") (forward-char))))
;;;###autoload
(defun narf/-org-capture-changelog ()
;; TODO
)
;;;###autoload
(defun narf/-org-capture-choose ()
;; TODO
)
(provide 'defuns-org)
;;; defuns-org.el ends here

View file

@ -1,45 +0,0 @@
;;; macros-org.el
;;;###autoload
(defmacro define-org-link! (type directory &optional id-func)
(setq directory (f-slash directory))
(let* ((type-str (symbol-name type))
(link-sym (intern (format "narf/org-link-%s" type-str)))
(dir-var (intern (format "org-directory-%s" type-str))))
`(progn
(defvar ,dir-var ,(expand-file-name directory org-directory))
(defun ,(intern (format "narf/helm-org-%s" type-str)) ()
(interactive)
(let ((default-directory ,directory))
(helm-deft)))
(defun ,link-sym (id)
(let ((path (f-glob (format "%s*.org" id) ,directory)))
(unless path
(error "ID not found: %s" id))
(org-open-file (car path) t)))
(org-add-link-type ,type-str ',link-sym)
(defun ,(intern (format "narf/org-%s-at-pt" type-str)) ()
(interactive)
(let* ((id (or (narf/org-get-property ,type-str)
(thing-at-point 'word t)))
(path (f-glob (format "%s*.org" id) ,dir-var)))
(unless path
(user-error "Couldn't find anything with %s (%s in %s)" id path ,directory))
(org-open-file (car path) t)))
(defun ,(intern (format "org-%s-complete-link" type-str)) ()
(let* ((default-directory (f-slash ,dir-var))
(file (org-iread-file-name ">>> "))
(relpath (f-relative file ,dir-var)))
(when (and (not (file-exists-p file))
(y-or-n-p (format "Create %s?" relpath)))
(write-region "" nil file)
(message "Created %s" file))
(format "%s:%s" ,type-str ,(if id-func `(funcall ,id-func relpath) 'relpath))
)))))
(provide 'macros-org)
;;; macros-org.el ends here