Large org-mode update

including improved shackle integration for agenda and other popups
This commit is contained in:
Henrik Lissner 2016-03-06 22:54:04 -05:00
parent 47874e7934
commit 59eebb95c9
5 changed files with 148 additions and 66 deletions

View file

@ -7,12 +7,16 @@
;;;###autoload
(defun narf/org-start ()
(interactive)
(narf:workgroup-new nil "*ORG*" t)
(cd org-directory)
(let ((helm-full-frame t))
(helm-find-files nil))
(save-excursion
(neotree-show)))
(let ((wg (wg-get-workgroup "*ORG*" t))
orig-win)
(ignore-errors
(if (eq wg (wg-current-workgroup t))
(wg-switch-to-workgroup wg)
(narf:workgroup-new nil "*ORG*" t)))
(setq orig-win (selected-window))
(find-file (expand-file-name "Todo.org" org-directory))
(narf/neotree)
(select-window orig-win t)))
;;;###autoload
(defun narf/org-notebook-new ()
@ -37,8 +41,7 @@
;;;###autoload
(defun narf/org-download-dnd (uri action)
(if (and (eq major-mode 'org-mode)
(not (image-type-from-file-name uri)))
(if (eq major-mode 'org-mode)
(narf:org-attach uri)
(let ((dnd-protocol-alist
(rassq-delete-all 'narf/org-download-dnd (copy-alist dnd-protocol-alist))))
@ -49,8 +52,9 @@
(interactive "<a>")
(if uri
(let* ((rel-path (org-download--fullname uri))
(new-path (f-expand rel-path)))
(cond ((string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) "://") uri)
(new-path (f-expand rel-path))
(image-p (image-type-from-file-name uri)))
(cond ((string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) ":/") uri)
(url-copy-file uri new-path))
(t (copy-file uri new-path)))
(unless new-path
@ -59,9 +63,12 @@
(org-insert-link nil (format "./%s" rel-path)
(concat (buffer-substring-no-properties (region-beginning) (region-end))
" " (narf/org-attach-icon rel-path)))
(insert (format "%s [[./%s][%s]]"
(narf/org-attach-icon rel-path)
rel-path (f-filename rel-path))))
(insert (if image-p
(format "[[./%s]]" rel-path)
(format "%s [[./%s][%s]]"
(narf/org-attach-icon rel-path)
rel-path (f-filename rel-path)))))
(when (string-match-p (regexp-opt '("jpg" "jpeg" "gif" "png")) (f-ext rel-path))
(org-toggle-inline-images)))
(let ((attachments (narf-org-attachments)))
@ -84,23 +91,27 @@
;;;###autoload
(defun narf/org-attachments ()
(let ((attachments '())
element
file)
(save-excursion
(goto-char (point-min))
(while (progn (org-next-link) (not org-link-search-failed))
(setq element (org-element-lineage (org-element-context) '(link) t))
(when element
(setq file (expand-file-name (org-element-property :path element)))
(when (and (string= (org-element-property :type element) "file")
(string= (concat (f-base (f-dirname file)) "/") org-attach-directory)
(file-exists-p file))
(push file attachments)))))
(-distinct attachments)))
"Retrieves a list of all the attachments pertinent to the currect org-mode buffer."
(org-save-outline-visibility nil
(let ((attachments '())
element
file)
(when (> (length (f-glob (concat (f-slash org-attach-directory) "*"))) 0)
(save-excursion
(goto-char (point-min))
(while (progn (org-next-link) (not org-link-search-failed))
(setq element (org-element-lineage (org-element-context) '(link) t))
(when element
(setq file (expand-file-name (org-element-property :path element)))
(when (and (string= (org-element-property :type element) "file")
(string= (concat (f-base (f-dirname file)) "/") org-attach-directory)
(file-exists-p file))
(push file attachments))))))
(-distinct attachments))))
;;;###autoload
(defun narf/org-cleanup-attachments ()
"Deletes any attachments that are no longer present in the org-mode buffer."
(let* ((attachments (narf/org-attachments))
(to-delete (-difference narf-org-attachments-list attachments)))
(mapc (lambda (f)

View file

@ -26,9 +26,31 @@
(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-indent ()
(interactive)
(cond
((and (org-on-heading-p)
(looking-back "^\\*+ +" (line-beginning-position)))
(ignore-errors
(org-demote)))
(t (call-interactively 'self-insert-command))))
;;;###autoload
(defun narf/org-dedent ()
(interactive)
(cond
((and (org-on-heading-p)
(looking-back "^\\*+ +" (line-beginning-position)))
(ignore-errors
(org-promote)))
(t (call-interactively 'self-insert-command))))
;;;###autoload
(defun narf/org-insert-item (direction)
"Inserts a new heading or item, depending on the context."
"Inserts a new heading or item, depending on the context. I use this instead of
`org-insert-item' or `org-insert-heading' because they try to do too much and end up doing
this otherwise simple task wrong (e.g. whitespace in the wrong places)."
(interactive)
(let* ((context (org-element-lineage
(org-element-context)
@ -36,13 +58,15 @@
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)))
(let ((marker (org-element-property :bullet context)))
(cl-case direction
('below
(goto-char (line-end-position))
(insert (concat "\n" marker)))
('above
(goto-char (line-beginning-position))
(insert marker)
(save-excursion (insert "\n")))))
(when (org-element-property :checkbox context)
(insert "[ ] ")))
((memq type '(table table-row))
@ -52,14 +76,31 @@
('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))))
(let ((level (save-excursion
(org-back-to-heading)
(org-element-property
:level (org-element-lineage (org-element-context)
'(headline) t)))))
(cl-case direction
('below
(let ((at-eol (= (point) (1- (line-end-position)))))
(goto-char (line-end-position))
(org-end-of-subtree)
(insert (concat "\n"
(when (= level 1)
(if at-eol
(ignore (cl-incf level))
"\n"))
(make-string level ?*)
" "))))
('above
(org-back-to-heading)
(org-insert-heading)
(when (= level 1)
(save-excursion (evil-open-above 1))
(save-excursion (insert "\n")))))
(when (org-element-property :todo-type context)
(org-todo 'todo)))))
(evil-append-line 1)))
;;;###autoload
@ -82,6 +123,9 @@
(type (org-element-type context))
(value (org-element-property :value context)))
(cond
((memq type '(planning timestamp))
(org-follow-timestamp-link))
((memq type '(table table-row))
(if (org-element-property :tblfm (org-element-property :parent context))
(org-table-recalculate t)
@ -296,5 +340,12 @@ re-align the table if necessary. (Necessary because org-mode has a
(skip-chars-backward "^|\n\r")
(when (org-looking-at-p " ") (forward-char))))
;;;###autoload (autoload 'narf:org-link "defuns-org" nil t)
(evil-define-command narf:org-link (link)
(interactive "<a>")
(let ((beg evil-visual-beginning)
(end evil-visual-end))
(org-insert-link nil link (when (and beg end) (buffer-substring-no-properties beg end)))))
(provide 'defuns-org)
;;; defuns-org.el ends here