Move lang/org => org/*
Since lang/org has grown (and is expected to grow much, much more), it has been given its own module category. Concerns #129, #138
This commit is contained in:
parent
576a91b66c
commit
d2d4166b42
31 changed files with 774 additions and 721 deletions
|
@ -1,52 +0,0 @@
|
|||
;;; lang/org/autoload/attach.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defun +org--attach-icon (path)
|
||||
(char-to-string (pcase (downcase (file-name-extension path))
|
||||
("jpg" ?) ("jpeg" ?) ("png" ?) ("gif" ?)
|
||||
("pdf" ?)
|
||||
("ppt" ?) ("pptx" ?)
|
||||
("xls" ?) ("xlsx" ?)
|
||||
("doc" ?) ("docx" ?)
|
||||
("ogg" ?) ("mp3" ?) ("wav" ?)
|
||||
("mp4" ?) ("mov" ?) ("avi" ?)
|
||||
("zip" ?) ("gz" ?) ("tar" ?) ("7z" ?) ("rar" ?)
|
||||
(_ ?))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-cleanup-attachments ()
|
||||
;; "Deletes any attachments that are no longer present in the org-mode buffer."
|
||||
(let* ((attachments-local (+org-attachments))
|
||||
(attachments (directory-files org-attach-directory t "^[^.]" t))
|
||||
(to-delete (cl-set-difference attachments-local attachments)))
|
||||
;; TODO
|
||||
to-delete))
|
||||
|
||||
(defun +org-attachments ()
|
||||
(unless (eq major-mode 'org-mode)
|
||||
(user-error "Not an org buffer"))
|
||||
(org-save-outline-visibility nil
|
||||
(let ((attachments '())
|
||||
element)
|
||||
(when (and (file-directory-p org-attach-directory)
|
||||
(> (length (file-expand-wildcards (expand-file-name "*" org-attach-directory))) 0))
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (progn (org-next-link) (not org-link-search-failed))
|
||||
(setq element (org-element-context))
|
||||
(when-let (file (and (eq (org-element-type element) 'link)
|
||||
(expand-file-name (org-element-property :path element))))
|
||||
(when (and (string= (org-element-property :type element) "file")
|
||||
(string= (concat (file-name-base (directory-file-name (file-name-directory file))) "/")
|
||||
org-attach-directory)
|
||||
(file-exists-p file))
|
||||
(push file attachments))))))
|
||||
(cl-remove-duplicates attachments))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-download-dnd (uri action)
|
||||
(if (eq major-mode 'org-mode)
|
||||
(doom:org-attach uri) ;; FIXME
|
||||
(let ((dnd-protocol-alist
|
||||
(rassq-delete-all '+org-download-dnd (copy-alist dnd-protocol-alist))))
|
||||
(dnd-handle-one-url nil action uri))))
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
;;; lang/org/autoload/babel.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/edit-special-same-window ()
|
||||
(interactive)
|
||||
(let ((shackle-rules '(("^\\*Org Src" :align t :select t :regexp t :noesc t :same t))))
|
||||
(call-interactively #'org-edit-special)
|
||||
;; FIXME too tightly coupled with doom-buffer-mode
|
||||
(when (fboundp 'solaire-mode)
|
||||
(solaire-mode +1))))
|
|
@ -1,11 +0,0 @@
|
|||
;;; lang/org/autoload/capture.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/capture (&optional key string)
|
||||
"Initializes the current frame as a pop-up `org-capture' frame."
|
||||
(interactive)
|
||||
(let ((key (or key "n"))
|
||||
(string (unless (string-empty-p string) string)))
|
||||
(if string
|
||||
(org-capture-string string key)
|
||||
(org-capture nil key))))
|
|
@ -1,41 +0,0 @@
|
|||
;;; lang/org/autoload/evil.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload (autoload '+org:capture "lang/org/autoload/evil" nil t)
|
||||
(evil-define-operator +org:capture (&optional beg end)
|
||||
"Send a selection to `doom/org-capture'."
|
||||
:move-point nil :type inclusive
|
||||
(interactive "<r>")
|
||||
(org-capture-string
|
||||
(when (and (evil-visual-state-p) beg end)
|
||||
(buffer-substring beg end))))
|
||||
|
||||
;;;###autoload (autoload '+org:attach "lang/org/autoload/evil" nil t)
|
||||
(evil-define-command +org:attach (&optional uri)
|
||||
(interactive "<a>")
|
||||
(unless (eq major-mode 'org-mode)
|
||||
(user-error "Not in an org-mode buffer"))
|
||||
(if uri
|
||||
(let* ((rel-path (org-download--fullname uri))
|
||||
(new-path (expand-file-name 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
|
||||
(user-error "No file was provided"))
|
||||
(if (evil-visual-state-p)
|
||||
(org-insert-link nil (format "./%s" rel-path)
|
||||
(concat (buffer-substring-no-properties (region-beginning) (region-end))
|
||||
" " (doom--org-attach-icon rel-path)))
|
||||
|
||||
(insert (if image-p
|
||||
(format "[[./%s]] " rel-path)
|
||||
(format "%s [[./%s][%s]] "
|
||||
(doom--org-attach-icon rel-path)
|
||||
rel-path (file-name-nondirectory (directory-file-name rel-path))))))
|
||||
(when (string-match-p (regexp-opt '("jpg" "jpeg" "gif" "png")) (file-name-extension rel-path))
|
||||
(org-redisplay-inline-images)))
|
||||
(let ((default-directory ".attach/"))
|
||||
(if (file-exists-p default-directory)
|
||||
(call-interactively 'find-file)
|
||||
(user-error "No attachments")))))
|
|
@ -1,36 +0,0 @@
|
|||
;;; lang/org/autoload/notebook.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-mode-notes-dir ()
|
||||
"Return the directory were `major-mode's org notes files are."
|
||||
(if-let (name (cdr (assq major-mode +org-notes-code-alist)))
|
||||
(expand-file-name (concat name "/") +org-code-notes-dir)
|
||||
(let ((mode-name (s-replace "+" "p" (s-chop-suffix "-mode" (symbol-name major-mode)))))
|
||||
(expand-file-name (concat mode-name "/") +org-code-notes-dir))))
|
||||
|
||||
(defun +org--explore-notes (dir)
|
||||
(unless (file-directory-p dir)
|
||||
(error "Directory doesn't exist: %s" dir))
|
||||
(if (fboundp '+evil/neotree)
|
||||
(neotree-dir dir)
|
||||
(let ((default-directory dir))
|
||||
(call-interactively (command-remapping 'find-file)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/browse-notes-for-major-mode ()
|
||||
"Browse org notes in `+org-code-notes-dir' in neotree, ido, ivy or helm --
|
||||
whichever is available."
|
||||
(interactive)
|
||||
(let ((dir (+org-mode-notes-dir)))
|
||||
(unless (file-in-directory-p dir +org-code-notes-dir)
|
||||
(error "Invalid location for %s notes: %s" major-mode (abbreviate-file-name dir)))
|
||||
(unless (file-directory-p dir)
|
||||
(make-directory dir t))
|
||||
(+org--explore-notes dir)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/browse-notes-for-project ()
|
||||
"Browse org notes in `+org-project-notes-dir' in neotree, ido, ivy or helm --
|
||||
whichever is available."
|
||||
(interactive)
|
||||
(+org--explore-notes +org-project-notes-dir))
|
|
@ -1,216 +0,0 @@
|
|||
;;; lang/org/autoload/org.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/indent ()
|
||||
"Indent the current item (header or item). Otherwise, forward to
|
||||
`self-insert-command'."
|
||||
(interactive)
|
||||
(cond ((org-at-item-p)
|
||||
(org-indent-item-tree))
|
||||
((org-at-heading-p)
|
||||
(ignore-errors (org-demote)))
|
||||
((org-in-src-block-p t)
|
||||
(doom/dumb-indent))
|
||||
(t
|
||||
(call-interactively #'self-insert-command))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/indent-or-next-field-or-yas-expand ()
|
||||
"Depending on the context either a) indent the current line, b) go the next
|
||||
table field or c) run `yas-expand'."
|
||||
(interactive)
|
||||
(call-interactively
|
||||
(cond ((and (bound-and-true-p yas-minor-mode)
|
||||
(yas--templates-for-key-at-point))
|
||||
#'yas-expand)
|
||||
((org-at-table-p)
|
||||
#'org-table-next-field)
|
||||
(t
|
||||
#'+org/indent))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/dedent ()
|
||||
"Dedent the current item (header or item). Otherwise, forward to
|
||||
`self-insert-command'."
|
||||
(interactive)
|
||||
(cond ((org-at-item-p)
|
||||
(org-list-indent-item-generic
|
||||
-1 nil
|
||||
(save-excursion
|
||||
(when (org-region-active-p)
|
||||
(goto-char (region-beginning)))
|
||||
(org-list-struct))))
|
||||
((org-at-heading-p)
|
||||
(ignore-errors (org-promote)))
|
||||
(t
|
||||
(call-interactively #'self-insert-command))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/dedent-or-prev-field ()
|
||||
"Depending on the context either dedent the current item or go the previous
|
||||
table field."
|
||||
(interactive)
|
||||
(call-interactively
|
||||
(if (org-at-table-p)
|
||||
#'org-table-previous-field
|
||||
#'+org/dedent)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/insert-item (direction)
|
||||
"Inserts a new heading, table cell or item, depending on the context.
|
||||
DIRECTION can be 'above or 'below.
|
||||
|
||||
I use this instead of `org-insert-item' or `org-insert-heading' which are too
|
||||
opinionated and perform this simple task incorrectly (e.g. whitespace in the
|
||||
wrong places)."
|
||||
(interactive)
|
||||
(let* ((context (org-element-lineage
|
||||
(org-element-context)
|
||||
'(table table-row headline inlinetask item plain-list)
|
||||
t))
|
||||
(type (org-element-type context)))
|
||||
(cond ((eq type 'item)
|
||||
(let ((marker (org-element-property :bullet context))
|
||||
(pad (save-excursion
|
||||
(back-to-indentation)
|
||||
(- (point) (line-beginning-position)))))
|
||||
(pcase direction
|
||||
('below
|
||||
(goto-char (line-end-position))
|
||||
(insert (concat "\n" (make-string pad ? ) marker)))
|
||||
('above
|
||||
(goto-char (line-beginning-position))
|
||||
(insert (make-string pad ? ) marker)
|
||||
(save-excursion (insert "\n")))))
|
||||
(when (org-element-property :checkbox context)
|
||||
(insert "[ ] ")))
|
||||
|
||||
((memq type '(table table-row))
|
||||
(pcase direction
|
||||
('below (org-table-insert-row t))
|
||||
('above (+org/table-prepend-row-or-shift-up))))
|
||||
|
||||
((memq type '(headline inlinetask plain-list))
|
||||
(let* ((subcontext (org-element-context))
|
||||
(level (save-excursion
|
||||
(org-back-to-heading)
|
||||
(org-element-property
|
||||
:level
|
||||
(if (eq (org-element-type subcontext) 'headline)
|
||||
subcontext
|
||||
1)))))
|
||||
(pcase 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))))
|
||||
|
||||
(t (user-error "Not a valid list, heading or table")))
|
||||
|
||||
(when (bound-and-true-p evil-mode)
|
||||
(evil-append-line 1))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/toggle-fold ()
|
||||
"Toggle the local fold at the point (as opposed to cycling through all levels
|
||||
with `org-cycle'). Also removes babel result blocks, if run from a code block."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(org-beginning-of-line)
|
||||
(cond ((org-in-src-block-p)
|
||||
(org-babel-remove-result))
|
||||
((org-at-heading-p)
|
||||
(outline-toggle-children))
|
||||
((org-at-item-p)
|
||||
(let ((window-beg (window-start)))
|
||||
(org-cycle)
|
||||
(set-window-start nil window-beg))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/toggle-checkbox ()
|
||||
"Toggle the presence of a checkbox in the current item."
|
||||
(interactive)
|
||||
(org-toggle-checkbox '(4)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/dwim-at-point ()
|
||||
"Do-what-I-mean at point. This includes following timestamp links, aligning
|
||||
tables, toggling checkboxes/todos, executing babel blocks, previewing latex
|
||||
fragments, opening links, or refreshing images."
|
||||
(interactive)
|
||||
(let* ((scroll-pt (window-start))
|
||||
(context (org-element-context))
|
||||
(type (org-element-type 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)
|
||||
(org-table-align)))
|
||||
|
||||
((org-element-property :checkbox (org-element-lineage context '(item) t))
|
||||
(let ((match (and (org-at-item-checkbox-p) (match-string 1))))
|
||||
(org-toggle-checkbox (if (equal match "[ ]") '(16)))))
|
||||
|
||||
((and (eq type 'headline)
|
||||
(org-element-property :todo-type context))
|
||||
(org-todo
|
||||
(if (eq (org-element-property :todo-type context) 'done) 'todo 'done)))
|
||||
|
||||
((and (eq type 'headline)
|
||||
(string= "ARCHIVE" (car-safe (org-get-tags))))
|
||||
(org-force-cycle-archived))
|
||||
|
||||
((eq type 'headline)
|
||||
(org-remove-latex-fragment-image-overlays)
|
||||
(org-toggle-latex-fragment '(4)))
|
||||
|
||||
((eq 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-toggle-latex-fragment))
|
||||
|
||||
((eq type 'link)
|
||||
(let ((path (org-element-property :path (org-element-lineage context '(link) t))))
|
||||
(if (and path (image-type-from-file-name path))
|
||||
(+org/refresh-inline-images)
|
||||
(org-open-at-point))))
|
||||
|
||||
(t (+org/refresh-inline-images)))
|
||||
(set-window-start nil scroll-pt)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/refresh-inline-images ()
|
||||
"Refresh image previews in the current heading/tree."
|
||||
(interactive)
|
||||
(if (> (length org-inline-image-overlays) 0)
|
||||
(org-remove-inline-images)
|
||||
(org-display-inline-images
|
||||
t t
|
||||
(if (org-before-first-heading-p)
|
||||
(line-beginning-position)
|
||||
(save-excursion (org-back-to-heading) (point)))
|
||||
(if (org-before-first-heading-p)
|
||||
(line-end-position)
|
||||
(save-excursion (org-end-of-subtree) (point))))))
|
|
@ -1,66 +0,0 @@
|
|||
;;; lang/org/autoload/tables.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/table-next-row ()
|
||||
"Go to the next row (same column) in the current table."
|
||||
(interactive)
|
||||
(if (org-at-table-p)
|
||||
(org-table-next-row)
|
||||
(org-down-element)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +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)
|
||||
(if (org-at-table-p)
|
||||
(progn
|
||||
(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))))
|
||||
(org-up-element)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/table-next-field ()
|
||||
(interactive)
|
||||
(if (org-at-table-p) (org-table-next-field) (org-end-of-line)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/table-previous-field ()
|
||||
(interactive)
|
||||
(if (org-at-table-p) (org-table-previous-field) (org-beginning-of-line)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/table-append-field-or-shift-right ()
|
||||
(interactive)
|
||||
(org-shiftmetaright)
|
||||
(when (org-at-table-p) (org-metaright)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/table-prepend-field-or-shift-left ()
|
||||
(interactive)
|
||||
(if (org-at-table-p) (org-shiftmetaright) (org-shiftmetaleft)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/table-append-row-or-shift-down ()
|
||||
(interactive)
|
||||
(org-shiftmetadown)
|
||||
(when (org-at-table-p) (org-metadown)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/table-prepend-row-or-shift-up ()
|
||||
(interactive)
|
||||
(if (org-at-table-p)
|
||||
(org-shiftmetadown)
|
||||
(org-shiftmetaup)))
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
;;; lang/org/autoload/util.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-get-property (name &optional _file) ; TODO Add FILE
|
||||
"Get a propery from an org file."
|
||||
(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))))
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue