From c7c1db477d534f46be5763f05541e00d5916bed0 Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 31 Mar 2021 01:40:24 +0100 Subject: unused org-mode stuff removed --- attic/counsel.org | 38 ++++++++-- lib/doc/jao-counsel-recoll.el | 60 --------------- lib/doc/jao-org-links.el | 169 +++++++++++++++++++++++++++++++++++++++++ lib/doc/jao-org-notes.el | 166 +++++++++++++++++++++++++++++++++++++++++ lib/org/jao-org-gnus.el | 72 ------------------ lib/org/jao-org-links.el | 170 ------------------------------------------ lib/org/jao-org-notes.el | 166 ----------------------------------------- lib/org/jao-org-popup.el | 31 -------- lib/org/jao-org-utils.el | 43 ----------- org.org | 36 +++++++-- 10 files changed, 396 insertions(+), 555 deletions(-) delete mode 100644 lib/doc/jao-counsel-recoll.el create mode 100644 lib/doc/jao-org-links.el create mode 100644 lib/doc/jao-org-notes.el delete mode 100644 lib/org/jao-org-gnus.el delete mode 100644 lib/org/jao-org-links.el delete mode 100644 lib/org/jao-org-notes.el delete mode 100644 lib/org/jao-org-popup.el delete mode 100644 lib/org/jao-org-utils.el diff --git a/attic/counsel.org b/attic/counsel.org index 5732fb7..6fbd591 100644 --- a/attic/counsel.org +++ b/attic/counsel.org @@ -64,13 +64,6 @@ :diminish) #+end_src * counsel add-ons -*** recoll - #+BEGIN_SRC emacs-lisp - (use-package jao-recoll) - (use-package jao-counsel-recoll - :after counsel - :bind (("C-c R" . jao-counsel-recoll))) - #+END_SRC *** notmuch #+begin_src emacs-lisp (use-package counsel-notmuch @@ -78,6 +71,37 @@ :config (with-eval-after-load "gnus-group" (define-key gnus-group-mode-map "Gg" 'counsel-notmuch))) #+end_src +*** recoll + #+begin_src emacs-lisp + (require 'jao-recoll) + (defvar jao-counsel-recoll--history nil) + (defun jao-counsel-recoll--function (str) + (let ((xs (counsel-recoll-function str))) + (cl-remove-if-not (lambda (x) (string-prefix-p "file://" x)) xs))) + + (defun jao-counsel-recoll (&optional initial-input) + (interactive) + (counsel-require-program "recoll") + (ivy-read "recoll: " 'jao-counsel-recoll--function + :initial-input initial-input + :dynamic-collection t + :history 'jao-counsel-recoll--history + :action (lambda (x) + (when (string-match "file://\\(.*\\)\\'" x) + (let ((file-name (match-string 1 x))) + (if (string-match "pdf$" x) + (jao-open-doc file-name) + (find-file file-name))))) + :unwind #'counsel-delete-process + :caller 'jao-counsel-recoll)) + + (defun jao-counsel-recoll--recoll (_s) (jao-recoll ivy-text)) + + (ivy-set-actions 'jao-counsel-recoll + '(("x" jao-counsel-recoll--recoll "List in buffer"))) + + (global-set-key (kbd "C-c R") #'jao-counsel-recoll) + #+end_src * ivy rich #+begin_src emacs-lisp (use-package ivy-rich diff --git a/lib/doc/jao-counsel-recoll.el b/lib/doc/jao-counsel-recoll.el deleted file mode 100644 index adae881..0000000 --- a/lib/doc/jao-counsel-recoll.el +++ /dev/null @@ -1,60 +0,0 @@ -;;; jao-counsel-recoll.el --- counsel and recoll -*- lexical-binding: t; -*- - -;; Copyright (C) 2020 jao - -;; Author: jao -;; Keywords: docs - -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Commentary: - -;; Helpers for using recoll with counsel - -;;; Code: - -(require 'jao-recoll) -(require 'counsel) -(require 'ivy) - -(defvar jao-counsel-recoll--history nil) -(defun jao-counsel-recoll--function (str) - (let ((xs (counsel-recoll-function str))) - (cl-remove-if-not (lambda (x) (string-prefix-p "file://" x)) xs))) - -;;;###autoload -(defun jao-counsel-recoll (&optional initial-input) - (interactive) - (counsel-require-program "recoll") - (ivy-read "recoll: " 'jao-counsel-recoll--function - :initial-input initial-input - :dynamic-collection t - :history 'jao-counsel-recoll--history - :action (lambda (x) - (when (string-match "file://\\(.*\\)\\'" x) - (let ((file-name (match-string 1 x))) - (if (string-match "pdf$" x) - (jao-open-doc file-name) - (find-file file-name))))) - :unwind #'counsel-delete-process - :caller 'jao-counsel-recoll)) - -(defun jao-counsel-recoll--recoll (_s) (jao-recoll ivy-text)) - -(ivy-set-actions 'jao-counsel-recoll - '(("x" jao-counsel-recoll--recoll "List in buffer"))) - - -(provide 'jao-counsel-recoll) -;;; jao-counsel-recoll.el ends here diff --git a/lib/doc/jao-org-links.el b/lib/doc/jao-org-links.el new file mode 100644 index 0000000..ee6af7c --- /dev/null +++ b/lib/doc/jao-org-links.el @@ -0,0 +1,169 @@ +;; -*- lexical-binding: t; -*- + +(require 'jao-maildir) +(require 'pdf-info) + +(defvar jao-org--sink-dir "./") +(defvar jao-org-open-pdf-fun 'jao-org--pdf-tools-open) + +(defun jao-org--pdf-go (page height) + (when page (pdf-view-goto-page page)) + (when height + (image-set-window-vscroll + (round (/ (* height (cdr (pdf-view-image-size))) (frame-char-height)))))) + +(defun jao-org--pdf-tools-open (path page &optional height) + (org-open-file path 1) + (jao-org--pdf-go path page)) + +(defun jao-org--pdf-open (path page &optional height) + (funcall (or jao-org-open-pdf-fun 'jao-org--pdf-tools-open) path page height)) + +(defun jao-org--pdf-p (file) (string-match-p ".*\\.pdf$" file)) + +(defun jao-org-links--open-pdf (link) + "Open LINK in pdf-view-mode." + (require 'pdf-tools) + (cond ((string-match "\\(.*\\)::\\([0-9]*\\)\\+\\+\\([[0-9]\\.*[0-9]*\\)" link) + (let* ((path (match-string 1 link)) + (page (string-to-number (match-string 2 link))) + (height (string-to-number (match-string 3 link)))) + (jao-org--pdf-open path page height))) + ((string-match "\\(.*\\)::\\([0-9]+\\)$" link) + (let* ((path (match-string 1 link)) + (page (max 1 (string-to-number (match-string 2 link))))) + (jao-org--pdf-open path page))) + (t (jao-org--pdf-open link nil)))) + +(defun jao-org-links--follow-doc (link) + (let* ((full-link (concat org-directory "/doc/" link)) + (dest-path (car (split-string full-link "::")))) + (when (not (file-exists-p dest-path)) + (let* ((sink-file (expand-file-name link jao-org--sink-dir)) + (real-file (if (file-exists-p sink-file) sink-file + (read-file-name "Import file: " + jao-org--sink-dir link link)))) + (shell-command (format "mv %s %s" real-file dest-path)))) + (if (jao-org--pdf-p dest-path) + (jao-org-links--open-pdf full-link) + (browse-url (format "file://%s" (expand-file-name dest-path)))))) + +(defun jao-org-links--complete-doc (&optional arg) + (let ((default-directory jao-org--sink-dir)) + (let ((f (replace-regexp-in-string "^file:" "doc:" + (org-file-complete-link arg)))) + (if (jao-org--pdf-p f) + (concat f "::" (read-from-minibuffer "Page: " "1")) + f)))) + +(defsubst jao-org--title->file (title) + (concat (mapconcat 'downcase (split-string title nil t) "-") ".pdf")) + +(defun jao-org--pdf-title (&optional fname) + (let ((base (file-name-base (or fname (pdf-view-buffer-file-name))))) + (capitalize (replace-regexp-in-string "-" " " base)))) + +(defvar-local jao--pdf-outline nil) + +(defun jao-org--pdf-section-title (&optional page) + (when (not jao--pdf-outline) + (setq-local jao--pdf-outline (pdf-info-outline))) + (let ((page (or page (pdf-view-current-page))) + (outline jao--pdf-outline) + (cur-page 0) + (cur-title (jao-org--pdf-title))) + (while (and (car outline) (< cur-page page)) + (setq cur-page (cdr (assoc 'page (car outline)))) + (when (<= cur-page page) + (setq cur-title (cdr (assoc 'title (car outline))))) + (setq outline (cdr outline))) + (replace-regexp-in-string "[[:blank:]]+" " " cur-title))) + +(defun jao-org-links-open-mail (fname) + (let ((group (jao-maildir-file-to-group fname)) + (id (with-temp-buffer + (insert-file fname) + (goto-char (point-min)) + (message-mode) + (not-modified) + (message-fetch-field "Message-ID")))) + (when (and group id) (org-gnus-follow-link group id)))) + +;;;###autoload +(defvar jao-org-links-pdf-store-fun nil) + +(defun jao-org-links--store-pdf-link () + (or (when (fboundp jao-org-links-pdf-store-fun) + (funcall jao-org-links-pdf-store-fun)) + (when (derived-mode-p 'pdf-view-mode) + (jao-org-links-store-pdf-link buffer-file-name + (pdf-view-current-page) + (jao-org--pdf-section-title))))) + +;;;###autoload +(defun jao-org-links-store-pdf-link (path page title) + (org-store-link-props + :type "doc" + :link (format "doc:%s::%d" (file-name-nondirectory path) page) + :description (format "%s (p. %d)" title page))) + +;;;###autoload +(defun jao-org-insert-doc (title) + (interactive "sDocument title: ") + (insert (format "[[doc:%s][%s]]" (jao-org--title->file title) title))) + +;;;###autoload +(defun jao-org-links-setup (sink-dir) + (interactive) + (org-link-set-parameters "doc" + :follow #'jao-org-links--follow-doc + :complete #'jao-org-links--complete-doc + :store #'jao-org-links--store-pdf-link) + (org-link-set-parameters "message" :follow #'jao-org-links-open-mail) + (setq jao-org--sink-dir (file-name-as-directory sink-dir))) + +(defvar jao-doc-notes-dir) + +;;;###autoload +(defun jao-org-org-to-pdf-file () + (expand-file-name (concat "doc/" (file-name-base buffer-file-name) ".pdf") + jao-org-notes-dir)) + +;;;###autoload +(defun jao-org-pdf-to-org-file (&optional file-name) + (let* ((file-name (or file-name buffer-file-name)) + (bn (file-name-base file-name)) + (rx (format "%s\\.org$" (regexp-quote bn)))) + (save-some-buffers nil + (lambda () + (string-prefix-p jao-org-notes-dir buffer-file-name))) + (or (car (directory-files-recursively jao-org-notes-dir rx)) + (let* ((dirs (seq-difference (directory-files jao-org-notes-dir) + '("." ".." "attic"))) + (dir (completing-read "Notes subdir: " dirs nil t))) + (expand-file-name (concat dir "/" bn ".org") jao-org-notes-dir))))) + +;;;###autoload +(defun jao-org-insert-doc-skeleton (&optional title) + (insert "#+title: " (or title (jao-org--pdf-title (buffer-file-name))) + "\n#+author:\n#+startup: latexpreview\n\n")) + +;;;###autoload +(defun jao-org-pdf-goto-org (arg) + (interactive "P") + (when (jao-org--pdf-p buffer-file-name) + (let* ((file (jao-org-pdf-to-org-file)) + (new (not (file-exists-p file))) + (title (jao-org--pdf-title))) + (when (or arg new) (org-store-link nil t)) + (find-file-other-window file) + (when new + (jao-org-insert-doc-skeleton title) + (org-insert-link))))) + +;;;###autoload +(defun jao-org-pdf-goto-org* () + (interactive) + (jao-org-pdf-goto-org t)) + +(provide 'jao-org-links) diff --git a/lib/doc/jao-org-notes.el b/lib/doc/jao-org-notes.el new file mode 100644 index 0000000..a1b9dbe --- /dev/null +++ b/lib/doc/jao-org-notes.el @@ -0,0 +1,166 @@ +;;; jao-org-notes.el --- A simple system for org note taking -*- lexical-binding: t; -*- + +;; Copyright (C) 2020, 2021 jao + +;; Author: jao +;; Keywords: tools + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; An org note per file, with consultable title and tags and a +;; backlinks approximation. + +;;; Code: + +(require 'org) +(require 'consult) + +(defvar jao-org-notes-dir (expand-file-name "notes" org-directory)) + +(defvar jao-org-notes--rg + (concat "rg --null --line-buffered --color=ansi --max-columns=250" + " --no-heading --line-number --smart-case" + " . -e \"^(#.(title|filetags): .*)ARG\" OPTS")) + +(defvar jao-org-notes--trx ":[0-9]+:#\\+\\(file\\)?\\(title\\|tags\\):") + +(defun jao-org-notes--clean-match (m) + (cons (replace-regexp-in-string jao-org-notes--trx " (\\2)" (car m)) (cdr m))) + +(defun jao-org-notes--matches (lines) + (let ((ms (consult--grep-matches lines))) + (mapcar #'jao-org-notes--clean-match ms))) + +(defun jao-org-notes--lookup (_ cands cand) + (or (cadr (assoc cand cands)) cand)) + +(defvar jao-org-notes--grep-history nil) + +(defun jao-org--grep (prompt &optional cat no-req) + (let ((default-directory (expand-file-name (or cat "") jao-org-notes-dir))) + (consult--read + (consult--async-command jao-org-notes--rg + (consult--async-transform jao-org-notes--matches)) + :prompt prompt + :lookup #'jao-org-notes--lookup + :initial consult-async-default-split + :add-history (concat consult-async-default-split (thing-at-point 'symbol)) + :require-match (not no-req) + :category 'jao-org-notes-lookup + :history '(:input jao-org-notes--grep-history) + :sort nil))) + +(defun jao-org-notes--cat () + (let* ((cats (seq-difference (directory-files jao-org-notes-dir) + '("." ".." "attic"))) + (cat (completing-read "Top level category: " cats))) + (cond ((file-exists-p (expand-file-name cat jao-org-notes-dir)) cat) + ((yes-or-no-p "New category, create?") cat) + (t (jao-roam--cat))))) + +(defun jao-org-notes--insert-title () + (let* ((cat (jao-org-notes--cat)) + (title (file-name-base (jao-org--grep "Title: " cat t))) + (title (replace-regexp-in-string "^#" "" title))) + (when (not (string-empty-p title)) + (let* ((base (replace-regexp-in-string " +" "-" (downcase title))) + (fname (expand-file-name (concat cat "/" base ".org") + jao-org-notes-dir)) + (exists? (file-exists-p fname))) + (find-file fname) + (when (not exists?) + (insert "#+title: " title "\n") + t))))) + +(defvar jao-org-notes--tags nil) + +(defun jao-org-notes--update-tags () + (setq jao-org-notes--tags + (org-global-tags-completion-table + (directory-files-recursively jao-org-notes-dir ".*\\.org")))) + +(defun jao-org-notes--read-tags () + (unless jao-org-notes--tags (jao-org-notes--update-tags)) + (completing-read-multiple "Tags: " jao-org-notes--tags)) + +(defun jao-org-notes--insert-tags () + (insert "#+filetags: " (mapconcat #'identity (jao-org-notes--read-tags) " ") "\n")) + +(defun jao-org-notes--insert-date () + (insert "#+date: ") + (org-insert-time-stamp (current-time)) + (insert "\n")) + +(defun jao-org-notes--template (k) + `(,k "Note" plain (file jao-org-notes-open-or-create) "\n- %a " + :immediate-finish t :jump-to-captured t)) + +;;;###autoload +(defun jao-org-notes-open () + "Search for a note file, matching tags and titles with completion." + (interactive) + (when-let (f (jao-org--grep "Search notes: ")) + (find-file f))) + +;;;###autoload +(defun jao-org-notes-open-or-create () + "Open or create a new note file, matching tags and titles with completion." + (interactive) + (when (jao-org-notes--insert-title) + (jao-org-notes--insert-date) + (jao-org-notes--insert-tags) + (jao-org-notes--update-tags) + (insert "#+link: ")) + (save-buffer) + (buffer-file-name)) + +;;;###autoload +(defun jao-org-notes-backlinks () + "Show a list of note files linking to the current one." + (interactive) + (consult-ripgrep jao-org-notes-dir + (concat "\\[\\[file:(.*/)?" (regexp-quote (buffer-name))))) + +;;;###autoload +(defun jao-org-notes-insert-tags () + "Insert a list of tags at point, with completing read." + (interactive) + (insert (mapconcat 'identity (jao-org-notes--read-tags) " "))) + +;;;###autoload +(defun jao-org-notes-insert-link () + "Select a note file (with completion) and insert a link to it." + (interactive) + (when-let (f (jao-org--grep "Notes file: ")) + (let ((rel-path (file-relative-name f default-directory)) + (title (with-current-buffer (find-file-noselect f) + (save-excursion + (goto-char (point-min)) + (when (re-search-forward "^#\\+title: \\(.+\\)" nil t) + (match-string 1)))))) + (insert (format "[[file:%s][%s]]" rel-path title))))) + +;;;###autoload +(defun jao-org-notes-setup (mnemonic) + "Set up the notes system, providing a mnemonic character for its org template." + (setq org-capture-templates + (add-to-list 'org-capture-templates (jao-org-notes--template mnemonic))) + (add-to-list 'org-agenda-files jao-org-notes-dir) + (when (fboundp 'org-capture-upgrade-templates) + (org-capture-upgrade-templates org-capture-templates))) + +(provide 'jao-org-notes) +;;; jao-org-notes.el ends here diff --git a/lib/org/jao-org-gnus.el b/lib/org/jao-org-gnus.el deleted file mode 100644 index cdeec65..0000000 --- a/lib/org/jao-org-gnus.el +++ /dev/null @@ -1,72 +0,0 @@ -;; Support for saving Gnus messages by Message-ID -(defun mde-org-gnus-save-by-mid () - (when (memq major-mode '(gnus-summary-mode gnus-article-mode)) - (when (eq major-mode 'gnus-article-mode) - (gnus-article-show-summary)) - (let* ((group gnus-newsgroup-name) - (method (gnus-find-method-for-group group))) - (when (memq (car method) '(nnml nntp)) - (let* ((article (gnus-summary-article-number)) - (header (gnus-summary-article-header article)) - (from (mail-header-from header)) - (message-id - (save-match-data - (let ((mid (mail-header-id header))) - (if (string-match "<\\(.*\\)>" mid) - (match-string 1 mid) - (error "Malformed message ID header %s" mid))))) - (date (mail-header-date header)) - (subject (gnus-summary-subject-string))) - (org-store-link-props :type "mid" :from from :subject subject - :message-id message-id :group group - :link (org-make-link "mid:" message-id)) - (apply 'org-store-link-props - :description (org-email-link-description) - org-store-link-plist) - t))))) - -(defvar mde-mid-resolve-methods '() - "List of methods to try when resolving message ID's. For Gnus, -it is a cons of 'gnus and the select (type and name).") -(setq mde-mid-resolve-methods - '((gnus nnml ""))) - -(defvar mde-org-gnus-open-level 1 - "Level at which Gnus is started when opening a link") -(defun mde-org-gnus-open-message-link (msgid) - "Open a message link with Gnus" - (require 'gnus) - (require 'org-table) - (catch 'method-found - (message "[MID linker] Resolving %s" msgid) - (dolist (method mde-mid-resolve-methods) - (cond - ((and (eq (car method) 'gnus) - (eq (cadr method) 'nnml)) - (funcall (cdr (assq 'gnus org-link-frame-setup)) - mde-org-gnus-open-level) - (when gnus-other-frame-object - (select-frame gnus-other-frame-object)) - (let* ((msg-info (nnml-find-group-number - (concat "<" msgid ">") - (cdr method))) - (group (and msg-info (car msg-info))) - (message (and msg-info (cdr msg-info))) - (qname (and group - (if (gnus-methods-equal-p - (cdr method) - gnus-select-method) - group - (gnus-group-full-name group (cdr method)))))) - (when msg-info - (gnus-summary-read-group qname nil t) - (gnus-summary-goto-article message nil t)) - (throw 'method-found t))) - (t (error "Unknown link type")))))) - -(eval-after-load 'org-gnus - '(progn - (add-to-list 'org-store-link-functions 'mde-org-gnus-save-by-mid) - (org-add-link-type "mid" 'mde-org-gnus-open-message-link))) - -(provide 'jao-org-gnus) diff --git a/lib/org/jao-org-links.el b/lib/org/jao-org-links.el deleted file mode 100644 index 2882f7a..0000000 --- a/lib/org/jao-org-links.el +++ /dev/null @@ -1,170 +0,0 @@ -;; -*- lexical-binding: t; -*- - -(require 'jao-org-utils) -(require 'jao-maildir) -(require 'pdf-info) - -(defvar jao-org--sink-dir "./") -(defvar jao-org-open-pdf-fun 'jao-org--pdf-tools-open) - -(defun jao-org--pdf-go (page height) - (when page (pdf-view-goto-page page)) - (when height - (image-set-window-vscroll - (round (/ (* height (cdr (pdf-view-image-size))) (frame-char-height)))))) - -(defun jao-org--pdf-tools-open (path page &optional height) - (org-open-file path 1) - (jao-org--pdf-go path page)) - -(defun jao-org--pdf-open (path page &optional height) - (funcall (or jao-org-open-pdf-fun 'jao-org--pdf-tools-open) path page height)) - -(defun jao-org--pdf-p (file) (string-match-p ".*\\.pdf$" file)) - -(defun jao-org-links--open-pdf (link) - "Open LINK in pdf-view-mode." - (require 'pdf-tools) - (cond ((string-match "\\(.*\\)::\\([0-9]*\\)\\+\\+\\([[0-9]\\.*[0-9]*\\)" link) - (let* ((path (match-string 1 link)) - (page (string-to-number (match-string 2 link))) - (height (string-to-number (match-string 3 link)))) - (jao-org--pdf-open path page height))) - ((string-match "\\(.*\\)::\\([0-9]+\\)$" link) - (let* ((path (match-string 1 link)) - (page (max 1 (string-to-number (match-string 2 link))))) - (jao-org--pdf-open path page))) - (t (jao-org--pdf-open link nil)))) - -(defun jao-org-links--follow-doc (link) - (let* ((full-link (concat org-directory "/doc/" link)) - (dest-path (car (split-string full-link "::")))) - (when (not (file-exists-p dest-path)) - (let* ((sink-file (expand-file-name link jao-org--sink-dir)) - (real-file (if (file-exists-p sink-file) sink-file - (read-file-name "Import file: " - jao-org--sink-dir link link)))) - (shell-command (format "mv %s %s" real-file dest-path)))) - (if (jao-org--pdf-p dest-path) - (jao-org-links--open-pdf full-link) - (browse-url (format "file://%s" (expand-file-name dest-path)))))) - -(defun jao-org-links--complete-doc (&optional arg) - (let ((default-directory jao-org--sink-dir)) - (let ((f (replace-regexp-in-string "^file:" "doc:" - (org-file-complete-link arg)))) - (if (jao-org--pdf-p f) - (concat f "::" (read-from-minibuffer "Page: " "1")) - f)))) - -(defsubst jao-org--title->file (title) - (concat (mapconcat 'downcase (split-string title nil t) "-") ".pdf")) - -(defun jao-org--pdf-title (&optional fname) - (let ((base (file-name-base (or fname (pdf-view-buffer-file-name))))) - (capitalize (replace-regexp-in-string "-" " " base)))) - -(defvar-local jao--pdf-outline nil) - -(defun jao-org--pdf-section-title (&optional page) - (when (not jao--pdf-outline) - (setq-local jao--pdf-outline (pdf-info-outline))) - (let ((page (or page (pdf-view-current-page))) - (outline jao--pdf-outline) - (cur-page 0) - (cur-title (jao-org--pdf-title))) - (while (and (car outline) (< cur-page page)) - (setq cur-page (cdr (assoc 'page (car outline)))) - (when (<= cur-page page) - (setq cur-title (cdr (assoc 'title (car outline))))) - (setq outline (cdr outline))) - (replace-regexp-in-string "[[:blank:]]+" " " cur-title))) - -(defun jao-org-links-open-mail (fname) - (let ((group (jao-maildir-file-to-group fname)) - (id (with-temp-buffer - (insert-file fname) - (goto-char (point-min)) - (message-mode) - (not-modified) - (message-fetch-field "Message-ID")))) - (when (and group id) (org-gnus-follow-link group id)))) - -;;;###autoload -(defvar jao-org-links-pdf-store-fun nil) - -(defun jao-org-links--store-pdf-link () - (or (when (fboundp jao-org-links-pdf-store-fun) - (funcall jao-org-links-pdf-store-fun)) - (when (derived-mode-p 'pdf-view-mode) - (jao-org-links-store-pdf-link buffer-file-name - (pdf-view-current-page) - (jao-org--pdf-section-title))))) - -;;;###autoload -(defun jao-org-links-store-pdf-link (path page title) - (org-store-link-props - :type "doc" - :link (format "doc:%s::%d" (file-name-nondirectory path) page) - :description (format "%s (p. %d)" title page))) - -;;;###autoload -(defun jao-org-insert-doc (title) - (interactive "sDocument title: ") - (insert (format "[[doc:%s][%s]]" (jao-org--title->file title) title))) - -;;;###autoload -(defun jao-org-links-setup (sink-dir) - (interactive) - (org-link-set-parameters "doc" - :follow #'jao-org-links--follow-doc - :complete #'jao-org-links--complete-doc - :store #'jao-org-links--store-pdf-link) - (org-link-set-parameters "message" :follow #'jao-org-links-open-mail) - (setq jao-org--sink-dir (file-name-as-directory sink-dir))) - -(defvar jao-doc-notes-dir) - -;;;###autoload -(defun jao-org-org-to-pdf-file () - (expand-file-name (concat "doc/" (file-name-base buffer-file-name) ".pdf") - jao-org-notes-dir)) - -;;;###autoload -(defun jao-org-pdf-to-org-file (&optional file-name) - (let* ((file-name (or file-name buffer-file-name)) - (bn (file-name-base file-name)) - (rx (format "%s\\.org$" (regexp-quote bn)))) - (save-some-buffers nil - (lambda () - (string-prefix-p jao-org-notes-dir buffer-file-name))) - (or (car (directory-files-recursively jao-org-notes-dir rx)) - (let* ((dirs (seq-difference (directory-files jao-org-notes-dir) - '("." ".." "attic"))) - (dir (completing-read "Notes subdir: " dirs nil t))) - (expand-file-name (concat dir "/" bn ".org") jao-org-notes-dir))))) - -;;;###autoload -(defun jao-org-insert-doc-skeleton (&optional title) - (insert "#+title: " (or title (jao-org--pdf-title (buffer-file-name))) - "\n#+author:\n#+startup: latexpreview\n\n")) - -;;;###autoload -(defun jao-org-pdf-goto-org (arg) - (interactive "P") - (when (jao-org--pdf-p buffer-file-name) - (let* ((file (jao-org-pdf-to-org-file)) - (new (not (file-exists-p file))) - (title (jao-org--pdf-title))) - (when (or arg new) (org-store-link nil t)) - (find-file-other-window file) - (when new - (jao-org-insert-doc-skeleton title) - (org-insert-link))))) - -;;;###autoload -(defun jao-org-pdf-goto-org* () - (interactive) - (jao-org-pdf-goto-org t)) - -(provide 'jao-org-links) diff --git a/lib/org/jao-org-notes.el b/lib/org/jao-org-notes.el deleted file mode 100644 index a1b9dbe..0000000 --- a/lib/org/jao-org-notes.el +++ /dev/null @@ -1,166 +0,0 @@ -;;; jao-org-notes.el --- A simple system for org note taking -*- lexical-binding: t; -*- - -;; Copyright (C) 2020, 2021 jao - -;; Author: jao -;; Keywords: tools - -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Commentary: - -;; An org note per file, with consultable title and tags and a -;; backlinks approximation. - -;;; Code: - -(require 'org) -(require 'consult) - -(defvar jao-org-notes-dir (expand-file-name "notes" org-directory)) - -(defvar jao-org-notes--rg - (concat "rg --null --line-buffered --color=ansi --max-columns=250" - " --no-heading --line-number --smart-case" - " . -e \"^(#.(title|filetags): .*)ARG\" OPTS")) - -(defvar jao-org-notes--trx ":[0-9]+:#\\+\\(file\\)?\\(title\\|tags\\):") - -(defun jao-org-notes--clean-match (m) - (cons (replace-regexp-in-string jao-org-notes--trx " (\\2)" (car m)) (cdr m))) - -(defun jao-org-notes--matches (lines) - (let ((ms (consult--grep-matches lines))) - (mapcar #'jao-org-notes--clean-match ms))) - -(defun jao-org-notes--lookup (_ cands cand) - (or (cadr (assoc cand cands)) cand)) - -(defvar jao-org-notes--grep-history nil) - -(defun jao-org--grep (prompt &optional cat no-req) - (let ((default-directory (expand-file-name (or cat "") jao-org-notes-dir))) - (consult--read - (consult--async-command jao-org-notes--rg - (consult--async-transform jao-org-notes--matches)) - :prompt prompt - :lookup #'jao-org-notes--lookup - :initial consult-async-default-split - :add-history (concat consult-async-default-split (thing-at-point 'symbol)) - :require-match (not no-req) - :category 'jao-org-notes-lookup - :history '(:input jao-org-notes--grep-history) - :sort nil))) - -(defun jao-org-notes--cat () - (let* ((cats (seq-difference (directory-files jao-org-notes-dir) - '("." ".." "attic"))) - (cat (completing-read "Top level category: " cats))) - (cond ((file-exists-p (expand-file-name cat jao-org-notes-dir)) cat) - ((yes-or-no-p "New category, create?") cat) - (t (jao-roam--cat))))) - -(defun jao-org-notes--insert-title () - (let* ((cat (jao-org-notes--cat)) - (title (file-name-base (jao-org--grep "Title: " cat t))) - (title (replace-regexp-in-string "^#" "" title))) - (when (not (string-empty-p title)) - (let* ((base (replace-regexp-in-string " +" "-" (downcase title))) - (fname (expand-file-name (concat cat "/" base ".org") - jao-org-notes-dir)) - (exists? (file-exists-p fname))) - (find-file fname) - (when (not exists?) - (insert "#+title: " title "\n") - t))))) - -(defvar jao-org-notes--tags nil) - -(defun jao-org-notes--update-tags () - (setq jao-org-notes--tags - (org-global-tags-completion-table - (directory-files-recursively jao-org-notes-dir ".*\\.org")))) - -(defun jao-org-notes--read-tags () - (unless jao-org-notes--tags (jao-org-notes--update-tags)) - (completing-read-multiple "Tags: " jao-org-notes--tags)) - -(defun jao-org-notes--insert-tags () - (insert "#+filetags: " (mapconcat #'identity (jao-org-notes--read-tags) " ") "\n")) - -(defun jao-org-notes--insert-date () - (insert "#+date: ") - (org-insert-time-stamp (current-time)) - (insert "\n")) - -(defun jao-org-notes--template (k) - `(,k "Note" plain (file jao-org-notes-open-or-create) "\n- %a " - :immediate-finish t :jump-to-captured t)) - -;;;###autoload -(defun jao-org-notes-open () - "Search for a note file, matching tags and titles with completion." - (interactive) - (when-let (f (jao-org--grep "Search notes: ")) - (find-file f))) - -;;;###autoload -(defun jao-org-notes-open-or-create () - "Open or create a new note file, matching tags and titles with completion." - (interactive) - (when (jao-org-notes--insert-title) - (jao-org-notes--insert-date) - (jao-org-notes--insert-tags) - (jao-org-notes--update-tags) - (insert "#+link: ")) - (save-buffer) - (buffer-file-name)) - -;;;###autoload -(defun jao-org-notes-backlinks () - "Show a list of note files linking to the current one." - (interactive) - (consult-ripgrep jao-org-notes-dir - (concat "\\[\\[file:(.*/)?" (regexp-quote (buffer-name))))) - -;;;###autoload -(defun jao-org-notes-insert-tags () - "Insert a list of tags at point, with completing read." - (interactive) - (insert (mapconcat 'identity (jao-org-notes--read-tags) " "))) - -;;;###autoload -(defun jao-org-notes-insert-link () - "Select a note file (with completion) and insert a link to it." - (interactive) - (when-let (f (jao-org--grep "Notes file: ")) - (let ((rel-path (file-relative-name f default-directory)) - (title (with-current-buffer (find-file-noselect f) - (save-excursion - (goto-char (point-min)) - (when (re-search-forward "^#\\+title: \\(.+\\)" nil t) - (match-string 1)))))) - (insert (format "[[file:%s][%s]]" rel-path title))))) - -;;;###autoload -(defun jao-org-notes-setup (mnemonic) - "Set up the notes system, providing a mnemonic character for its org template." - (setq org-capture-templates - (add-to-list 'org-capture-templates (jao-org-notes--template mnemonic))) - (add-to-list 'org-agenda-files jao-org-notes-dir) - (when (fboundp 'org-capture-upgrade-templates) - (org-capture-upgrade-templates org-capture-templates))) - -(provide 'jao-org-notes) -;;; jao-org-notes.el ends here diff --git a/lib/org/jao-org-popup.el b/lib/org/jao-org-popup.el deleted file mode 100644 index eb5b24d..0000000 --- a/lib/org/jao-org-popup.el +++ /dev/null @@ -1,31 +0,0 @@ -;;; frame popups -;; http://metajack.im/2008/12/30/gtd-capture-with-emacs-orgmode/ -(defsubst jao-remember--frame-p () - (equal "*Remember*" (frame-parameter nil 'name))) - -(defadvice remember-finalize (after delete-remember-frame activate) - "Advise remember-finalize to close the frame if it is the remember frame" - (when (jao-remember--frame-p) (delete-frame))) - -(defadvice remember-destroy (after delete-remember-frame activate) - "Advise remember-destroy to close the frame if it is the remember frame" - (when (jao-remember--frame-p) (delete-frame))) - -;; make the frame contain a single window. by default org-remember -;; splits the window. -(defun jao-remember--delete-other-windows () - (when (jao-remember--frame-p) (delete-other-windows))) - -(add-hook 'remember-mode-hook 'jao-remember--delete-other-windows) - -(defun make-remember-frame () - "Create a new frame and run org-remember" - (interactive) - (make-frame-on-display (getenv "DISPLAY") - '((name . "*Remember*") - (width . 80) - (height . 10))) - (select-frame-by-name "*Remember*") - (org-remember nil ?x)) - -(provide 'jao-org-popup) \ No newline at end of file diff --git a/lib/org/jao-org-utils.el b/lib/org/jao-org-utils.el deleted file mode 100644 index 8d65ed7..0000000 --- a/lib/org/jao-org-utils.el +++ /dev/null @@ -1,43 +0,0 @@ -(require 'org) - -;;; links -(defun jao-org-link-at-point (&optional copy) - (when (thing-at-point-looking-at "\\[\\[\\([^]]+\\)\\]\\[[^]]+\\]\\]") - (when copy (kill-ring-save (match-beginning 1) (match-end 1))) - (match-string-no-properties 1))) - -(defun jao-org-copy-link-at-point () - (interactive) - (message "%s" (or (jao-org-link-at-point t) "No link at point"))) - -(defun jao-org-insert-link (url title) - (insert (format "[[%s][%s]]" url title))) - -;;; eldoc -(defun jao-org-eldoc--hook () - (set (make-local-variable 'eldoc-documentation-function) - 'jao-org-link-at-point) - (eldoc-mode)) - -;;;###autoload -(defun jao-org-utils-eldoc-setup () - (add-hook 'org-mode-hook 'jao-org-eldoc--hook)) - -;;; play fair with saveplace -(defun jao-org--show-if-hidden () - (when (outline-invisible-p) - (save-excursion - (outline-previous-visible-heading 1) - (org-show-subtree)))) - -;;; verifying org refile targets -(defun jao-org--refile-target-verify () - (not (looking-at-p ".*\\[\\[.+$"))) - -;;;###autoload -(defun jao-org-utils-setup () - (setq org-refile-target-verify-function 'jao-org--refile-target-verify) - (add-hook 'org-mode-hook 'jao-org--show-if-hidden t)) - - -(provide 'jao-org-utils) diff --git a/org.org b/org.org index 897fc41..9f935fb 100644 --- a/org.org +++ b/org.org @@ -234,6 +234,18 @@ (require 'ol-info nil t) (setq org-link-abbrev-alist '(("jao.io" "https://jao.io/"))) + (defun jao-org-link-at-point (&optional copy) + (when (thing-at-point-looking-at "\\[\\[\\([^]]+\\)\\]\\[[^]]+\\]\\]") + (when copy (kill-ring-save (match-beginning 1) (match-end 1))) + (match-string-no-properties 1))) + + (defun jao-org-copy-link-at-point () + (interactive) + (message "%s" (or (jao-org-link-at-point t) "No link at point"))) + + (defun jao-org-insert-link (url title) + (insert (format "[[%s][%s]]" url title))) + (defun jao-insert-eww-link () "Look for last eww buffer and insert an org link to it." (interactive) @@ -241,22 +253,34 @@ (let ((lnk (with-current-buffer b (format "[[%s][%s]]" (eww-current-url) (jao-eww--title))))) (insert lnk)))) - #+end_src -* jao-org - #+begin_src emacs-lisp - (use-package jao-org-utils) (use-package jao-org-links :commands jao-org-links-setup :bind (("C-c T" . jao-org-insert-doc))) - (jao-org-utils-setup) - (jao-org-utils-eldoc-setup) (jao-org-links-setup jao-sink-dir) (with-eval-after-load "pdf-view" (define-key pdf-view-mode-map (kbd "C-c o") #'jao-org-pdf-goto-org) (define-key pdf-view-mode-map (kbd "C-c O") #'jao-org-pdf-goto-org*)) + + #+end_src +* Eldoc + #+begin_src emacs-lisp + (defun jao-org-eldoc--hook () + (set (make-local-variable 'eldoc-documentation-function) + 'jao-org-link-at-point) + (eldoc-mode)) + (add-hook 'org-mode-hook 'jao-org-eldoc--hook) + #+end_src +* Savedoc + #+begin_src emacs-lisp + (defun jao-org--show-if-hidden () + (when (outline-invisible-p) + (save-excursion + (outline-previous-visible-heading 1) + (org-show-subtree)))) + (add-hook 'org-mode-hook 'jao-org--show-if-hidden t) #+end_src * Geiser and org #+begin_src emacs-lisp -- cgit v1.2.3