yeet
This commit is contained in:
304
.config/emacs/modules/lang/org/README.org
Normal file
304
.config/emacs/modules/lang/org/README.org
Normal file
@@ -0,0 +1,304 @@
|
||||
#+TITLE: lang/org
|
||||
#+DATE: February 19, 2017
|
||||
#+SINCE: 2.0
|
||||
#+STARTUP: inlineimages
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#plugins][Plugins]]
|
||||
- [[#hacks][Hacks]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#macos][MacOS]]
|
||||
- [[#arch-linux][Arch Linux]]
|
||||
- [[#nixos][NixOS]]
|
||||
- [[#windows][Windows]]
|
||||
- [[#features][Features]]
|
||||
- [[#invoking-the-org-capture-frame-from-outside-emacs][Invoking the org-capture frame from outside Emacs]]
|
||||
- [[#built-in-custom-link-types][Built-in custom link types]]
|
||||
- [[#configuration][Configuration]]
|
||||
- [[#changing-org-directory][Changing ~org-directory~]]
|
||||
- [[#changing-org-noter-notes-search-path][Changing ~org-noter-notes-search-path~]]
|
||||
- [[#troubleshooting][Troubleshooting]]
|
||||
- [[#org-roam][=org-roam=]]
|
||||
- [[#should-i-go-with-roam-v1-or-roam2-v2][Should I go with =+roam= (v1) or =+roam2= (v2)?]]
|
||||
- [[#migrating-your-existing-files-from-v1-roam-to-v2-roam2][Migrating your existing files from v1 (=+roam=) to v2 (=+roam2=)]]
|
||||
|
||||
* Description
|
||||
This module adds org-mode support to Doom Emacs, along with a number of
|
||||
adjustments, extensions and reasonable defaults to make it more performant and
|
||||
intuitive out of the box:
|
||||
|
||||
+ A custom, centralized attachment system that stores files in one place, rather
|
||||
than in the same directory as the input file(s) (only applies to attachments
|
||||
from files in/under =org-directory=).
|
||||
+ Executable code blocks with support for a variety of languages and tools
|
||||
(depending on what :lang modules are enabled).
|
||||
+ Supports an external org-capture workflow through the =bin/org-capture= shell
|
||||
script and ~+org-capture/open-frame~.
|
||||
+ A configuration for using org-mode for slide-show presentations or exporting
|
||||
org files to reveal.js slideshows.
|
||||
+ Drag-and-drop support for images (with inline preview) and media files (drops
|
||||
a file icon and a short link) (requires =+dragndrop= flag).
|
||||
+ Integration with pandoc, ipython, jupyter, reveal.js, beamer, and others
|
||||
(requires flags).
|
||||
+ Export-to-clipboard functionality, for copying text into formatted html,
|
||||
markdown or rich text to the clipboard (see ~+org/export-to-clipboard~ and
|
||||
~+org/export-to-clipboard-as-rich-text~).
|
||||
|
||||
#+begin_quote
|
||||
Org is a system for writing plain text notes with syntax highlighting, code
|
||||
execution, task scheduling, agenda management, and many more. The whole idea is
|
||||
that you can write notes and mix them with references to things like articles,
|
||||
images, and example code combined with the output of that code after it is
|
||||
executed.
|
||||
|
||||
https://www.mfoot.com/blog/2015/11/22/literate-emacs-configuration-with-org-mode/
|
||||
#+end_quote
|
||||
|
||||
** Module Flags
|
||||
+ =+brain= Enables [[https://github.com/Kungsgeten/org-brain][org-brain]] integration.
|
||||
+ =+dragndrop= Enables drag-and-drop support for images and files; inserts
|
||||
inline previews for images and an icon+link for other media types.
|
||||
+ =+gnuplot= Installs gnuplot & gnuplot-mode, which enables rendering images
|
||||
from gnuplot src blocks or plotting tables with ~org-plot/gnuplot~ (bound to
|
||||
=SPC m b p=, by default).
|
||||
+ =+hugo= Enables integration with [[https://gohugo.io][hugo]] to export from Emacs well-formed
|
||||
([[https://github.com/russross/blackfriday][blackfriday]]) markdown.
|
||||
+ =+ipython= (**DEPRECATED**) Enables ipython integration for babel.
|
||||
+ =+journal= Enables [[https://github.com/bastibe/org-journal][org-journal]] integration.
|
||||
+ =+jupyter= Enables Jupyter integration for babel.
|
||||
+ =+noter= Enables org-noter integration. Keeps notes in sync with a document.
|
||||
Requires [[https://github.com/politza/pdf-tools][pdf-tools]] (=:tools pdf=) or [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Document-View.html][DocView]] or [[https://github.com/wasamasa/nov.el][nov.el]] to be enabled.
|
||||
+ =+pandoc= Enables pandoc integration into the Org exporter.
|
||||
+ =+pomodoro= Enables a pomodoro timer for clocking time on tasks.
|
||||
+ =+present= Enables integration with reveal.js, beamer and org-tree-slide, so
|
||||
Emacs can be used for presentations. It automatically downloads [[https://github.com/hakimel/reveal.js][reveal.js]].
|
||||
+ =+pretty= Enables pretty unicode symbols for bullets and priorities, and
|
||||
better syntax highlighting for latex. Keep in mind: this can be expensive. If
|
||||
org becomes too slow, it'd be wise to disable this flag.
|
||||
+ =+roam= Enables integration with [[https://github.com/org-roam/org-roam-v1][org-roam v1]]. This requires ~sqlite3~ to be
|
||||
installed on your system. Incompatible with =+roam2=.
|
||||
+ =+roam2= Enables integration with [[https://github.com/org-roam/org-roam][org-roam v2]]. This requires ~sqlite3~ to be
|
||||
installed on your system. Incompatible with =+roam=.
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/hniksic/emacs-htmlize][htmlize]]
|
||||
+ [[https://github.com/astahlman/ob-async][ob-async]]
|
||||
+ [[https://github.com/rexim/org-cliplink][org-cliplink]]
|
||||
+ [[https://github.com/magit/orgit][orgit]]
|
||||
+ [[https://orgmode.org/][org-plus-contrib]]
|
||||
+ [[https://github.com/TobiasZawada/org-yt][org-yt]]
|
||||
+ [[https://github.com/jkitchin/ox-clip][ox-clip]]
|
||||
+ [[https://github.com/snosov1/toc-org][toc-org]]
|
||||
+ =:lang crystal=
|
||||
+ [[https://github.com/brantou/ob-crystal][ob-crystal]]
|
||||
+ =:lang go=
|
||||
+ [[https://github.com/pope/ob-go][ob-go]]
|
||||
+ =:lang nim=
|
||||
+ [[https://github.com/Lompik/ob-nim][ob-nim]]
|
||||
+ =:lang racket=
|
||||
+ [[https://github.com/DEADB17/ob-racket][ob-racket]]
|
||||
+ =:lang rest=
|
||||
+ [[https://github.com/alf/ob-restclient.el][ob-restclient]]
|
||||
+ =:lang rst=
|
||||
+ [[https://github.com/msnoigrs/ox-rst][ox-rst]]
|
||||
+ =:lang rust=
|
||||
+ [[https://github.com/micanzhang/ob-rust][ob-rust]]
|
||||
+ =:lang scala=
|
||||
+ [[https://github.com/zwild/ob-ammonite][ob-ammonite]]
|
||||
+ =:editor evil=
|
||||
+ [[https://github.com/Somelauw/evil-org-mode][evil-org]]
|
||||
+ =:tools pdf=
|
||||
+ [[https://github.com/fuxialexander/org-pdftools][org-pdftools]]
|
||||
+ =+dragndrop=
|
||||
+ [[https://github.com/abo-abo/org-download][org-download]]
|
||||
+ =+gnuplot=
|
||||
+ [[https://github.com/mkmcc/gnuplot-mode][gnuplot]]
|
||||
+ [[https://github.com/bruceravel/gnuplot-mode][gnuplot-mode]]
|
||||
+ =+hugo=
|
||||
+ [[https://github.com/kaushalmodi/ox-hugo][ox-hugo]]
|
||||
+ =+ipython=
|
||||
+ [[https://github.com/gregsexton/ob-ipython][ob-ipython]]
|
||||
+ =+jupyter=
|
||||
+ [[https://github.com/dzop/emacs-jupyter][jupyter]]
|
||||
+ =+pandoc=
|
||||
+ [[https://github.com/kawabata/ox-pandoc][ox-pandoc]]
|
||||
+ =+pomodoro=
|
||||
+ [[https://github.com/marcinkoziej/org-pomodoro][org-pomodoro]]
|
||||
+ =+present=
|
||||
+ [[https://github.com/anler/centered-window-mode][centered-window]]
|
||||
+ [[https://github.com/takaxp/org-tree-slide][org-tree-slide]]
|
||||
+ [[https://gitlab.com/oer/org-re-reveal][org-re-reveal]]
|
||||
+ =+pretty=
|
||||
+ [[https://github.com/integral-dw/org-superstar-mode][org-superstar]]
|
||||
+ [[https://github.com/harrybournis/org-fancy-priorities][org-fancy-priorities]]
|
||||
+ =+roam=
|
||||
+ [[https://github.com/org-roam/org-roam-v1][org-roam]] (v1)
|
||||
+ =+roam2=
|
||||
- [[https://github.com/org-roam/org-roam][org-roam]] (v2)
|
||||
+ =+noter=
|
||||
+ [[https://github.com/weirdNox/org-noter][org-noter]]
|
||||
|
||||
|
||||
** Hacks
|
||||
+ Adds support for a ~:sync~ parameter for org src blocks. This overrides
|
||||
~:async~.
|
||||
+ Gracefully degrades ~:async~ babel blocks to ~:sync~ when =ob-async= would
|
||||
cause errors or issues (such as with a ~:session~ parameter, which =ob-async=
|
||||
does not support, or when exporting org documents).
|
||||
+ The window is recentered when following links.
|
||||
+ The breadcrumbs displayed in eldoc when hovering over an org headline has been
|
||||
reworked to strip out link syntax and normalize font-size disparities.
|
||||
+ If =:ui workspaces= is enabled, persp-mode won't register org agenda buffers that
|
||||
are temporarily opened in the background.
|
||||
+ Temporary org agenda files aren't added to recentf.
|
||||
+ =file:= links are highlighted with the ~error~ face if they are broken.
|
||||
+ TAB was changed to toggle only the visibility state of the current subtree,
|
||||
rather than cycle through it recursively. This can be reversed with:
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(after! evil-org
|
||||
(remove-hook 'org-tab-first-hook #'+org-cycle-only-current-subtree-h))
|
||||
#+END_SRC
|
||||
+ (Evil users) Nearby tables are formatted when exiting insert or replace mode
|
||||
(see ~+org-enable-auto-reformat-tables-h~).
|
||||
+ Statistics cookies are updated when saving the buffer of exiting insert mode
|
||||
(see ~+org-enable-auto-update-cookies-h~).
|
||||
+ Org-protocol has been lazy loaded (see ~+org-init-protocol-lazy-loader-h~);
|
||||
loaded when the server receives a request for an org-protocol:// url.
|
||||
+ Babel and babel plugins are now lazy loaded (see
|
||||
~+org-init-babel-lazy-loader-h~); loaded when a src block is executed. No need
|
||||
to use ~org-babel-do-load-languages~ in your config, just install your babel
|
||||
packages to extend language support (and ensure its ~org-babel-execute:*~
|
||||
function is autoloaded).
|
||||
+ If a variable is used as a file path in ~org-capture-template~, it will be
|
||||
resolved relative to ~org-directory~, instead of ~default-directory~ (see
|
||||
~+org-capture-expand-variable-file-a~).
|
||||
|
||||
* Prerequisites
|
||||
Org has a few soft dependencies that you will need to make use of Org's more
|
||||
esoteric features:
|
||||
|
||||
+ For inline LaTeX previews, ~latex~ and ~dvipng~ is needed.
|
||||
+ To render GNUPlot images (with =+gnuplot= flag) the ~gnuplot~ program is
|
||||
needed.
|
||||
+ To execute babel code blocks, you need whatever dependencies those languages
|
||||
need. It is recommended you enable the associated =:lang= module and ensure
|
||||
its dependencies are met, e.g. install the =ruby= executable for ruby support.
|
||||
To use ~jupyter kernels~ you need the =+jupyter= flag, the associated kernel as
|
||||
well as the ~jupyter~ program.
|
||||
+ =org-roam= (with =+roam= or =+roam2= flag) requires =sqlite3= to be installed.
|
||||
|
||||
** MacOS
|
||||
#+BEGIN_SRC sh
|
||||
brew install --cask mactex
|
||||
brew install gnuplot
|
||||
#+END_SRC
|
||||
|
||||
** Arch Linux
|
||||
#+BEGIN_SRC sh
|
||||
pacman -S texlive-core texlive-bin texlive-science
|
||||
pacman -S gnuplot
|
||||
pacman -S jupyter # required by +jupyter
|
||||
#+END_SRC
|
||||
|
||||
** NixOS
|
||||
#+BEGIN_SRC nix
|
||||
environment.systemPackages = with pkgs; [
|
||||
# any less than medium isn't guaranteed to work
|
||||
texlive.combined.scheme-medium
|
||||
# required by +jupyter
|
||||
(python38.withPackages(ps: with ps; [jupyter]))
|
||||
];
|
||||
#+END_SRC
|
||||
|
||||
** TODO Windows
|
||||
|
||||
* Features
|
||||
** Invoking the org-capture frame from outside Emacs
|
||||
The simplest way to use the org-capture frame is through the ~bin/org-capture~
|
||||
script. I'd recommend binding a shortcut key to it. If Emacs isn't running, it
|
||||
will spawn a temporary daemon for you.
|
||||
|
||||
Alternatively, you can call ~+org-capture/open-frame~ directly, e.g.
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
emacsclient --eval '(+org-capture/open-frame INTIAL-INPUT KEY)'
|
||||
#+END_SRC
|
||||
|
||||
** Built-in custom link types
|
||||
This module defines a number of custom link types in ~+org-init-custom-links-h~.
|
||||
They are (with examples):
|
||||
|
||||
+ ~doom-docs:news/2.1.0~ (=~/.emacs.d/docs/%s=)
|
||||
+ ~doom-modules:editor/evil/README.org~ (=~/.emacs.d/modules/%s=)
|
||||
+ ~doom-repo:issues~ (=https://github.com/hlissner/doom-emacs/%s=)
|
||||
+ ~doom:core/core.el~ (=~/.emacs.d/%s=)
|
||||
+ ~duckduckgo:search terms~
|
||||
+ ~gimages:search terms~ (Google Images)
|
||||
+ ~github:hlissner/doom-emacs~
|
||||
+ ~gmap:Toronto, Ontario~ (Google Maps)
|
||||
+ ~google:search terms~
|
||||
+ ~org:todo.org~ (={org-directory}/%s=)
|
||||
+ ~wolfram:sin(x^3)~
|
||||
+ ~wikipedia:Emacs~
|
||||
+ ~youtube:P196hEuA_Xc~ (link only)
|
||||
+ ~yt:P196hEuA_Xc~ (like =youtube=, but includes an inline preview of the video)
|
||||
|
||||
* Configuration
|
||||
** Changing ~org-directory~
|
||||
To modify ~org-directory~ it must be set /before/ =org= has loaded:
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
;; ~/.doom.d/config.el
|
||||
(setq org-directory "~/new/org/location/")
|
||||
#+END_SRC
|
||||
** Changing ~org-noter-notes-search-path~
|
||||
To modify ~org-noter-notes-search-path~ set:
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
;; ~/.doom.d/config.el
|
||||
(setq org-noter-notes-search-path '("~/notes/path/"))
|
||||
#+END_SRC
|
||||
|
||||
* Troubleshooting
|
||||
** =org-roam=
|
||||
*** Should I go with =+roam= (v1) or =+roam2= (v2)?
|
||||
Long story short: if you're new to =org-roam= and haven't used it, then you
|
||||
should go with =+roam2=; if you already have an ~org-roam-directory~ with the v1
|
||||
files in it, then you can keep use =+roam= for a time being.
|
||||
|
||||
V1 isn't actively maintained anymore and is now basically EOL. This means that
|
||||
the feature disparity between the both will continue to grow, while its existing
|
||||
bugs and problems won't be addressed, at least by the main maintainers. V2 can
|
||||
be considered as a complete rewrite of the package so it comes with a lot of
|
||||
breaking changes.
|
||||
|
||||
While v1 won't be actively maintained anymore, it still will be available in
|
||||
Doom for a while, at least until there will be a reliable tool that will migrate
|
||||
your data from v1 to v2.
|
||||
|
||||
To learn more about v2 you can use the next resources:
|
||||
- [[https://github.com/org-roam/org-roam/blob/master/doc/org-roam.org][Org-roam v2 Official Manual]]
|
||||
- [[https://github.com/org-roam/org-roam/wiki/Hitchhiker's-Rough-Guide-to-Org-roam-V2][Hitchhiker's Rough Guide to Org roam V2]]
|
||||
- [[https://blog.jethro.dev/posts/org_roam_v2/][Releasing Org-roam v2 - Jethro Kuan's blog]]
|
||||
- [[https://org-roam.discourse.group/t/org-roam-major-redesign/1198][Thread about the redesign from Org-Roam Discourse]]
|
||||
|
||||
*** Migrating your existing files from v1 (=+roam=) to v2 (=+roam2=)
|
||||
V2 comes with a migration wizard for v1 users. It's new, which means issues can
|
||||
appear during the migration process. Because of that, *don't forget to backup*
|
||||
your ~org-roam-directory~ before attempting to migrate.
|
||||
|
||||
In order to migrate from v1 to v2 using Doom follow the next steps:
|
||||
1. Enable =+roam2= flag (and disable =+roam= if it was previously enabled) in
|
||||
your =init.el=.
|
||||
2. Ensure your ~org-roam-directory~ points to a directory with your v1 files.
|
||||
3. Run =doom sync -u= in your shell.
|
||||
4. Restart Emacs (if it was previously opened) and run ~org-roam-migrate-wizard~
|
||||
command (=M-x org-roam-migrate-wizard RET=). The wizard will automatically
|
||||
attempt to backup your previous ~org-roam-directory~ to =org-roam.bak=, but
|
||||
just in case backup it yourself too.
|
||||
4. After the wizard is done you should be good to go. Verify the integrity of
|
||||
your data and whether it did everything as expected. In case of failure
|
||||
[[https://github.com/org-roam/org-roam/issues][report]] your issue.
|
||||
152
.config/emacs/modules/lang/org/autoload/contrib-ipython.el
Normal file
152
.config/emacs/modules/lang/org/autoload/contrib-ipython.el
Normal file
@@ -0,0 +1,152 @@
|
||||
;;; lang/org/autoload/contrib-ipython.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +ipython)
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-ob-ipython-initiate-session-a (&optional session params)
|
||||
"Create a session named SESSION according to PARAMS."
|
||||
(if (string= session "none")
|
||||
(error
|
||||
"ob-ipython currently only supports evaluation using a session.
|
||||
Make sure your src block has a :session param.")
|
||||
(when (not (string-suffix-p ".json" session t))
|
||||
(ob-ipython--create-kernel
|
||||
(ob-ipython--normalize-session
|
||||
session)
|
||||
(cdr (assoc :kernel params))))
|
||||
(ob-ipython--create-repl
|
||||
(ob-ipython--normalize-session
|
||||
session)
|
||||
params)))
|
||||
|
||||
(defun +org--ob-ipython-generate-local-path-from-remote (session host params)
|
||||
"Given a remote SESSION with PARAMS and corresponding HOST, copy remote config to local, start a jupyter console to generate a new one."
|
||||
(let* ((runtime-dir
|
||||
(cdr
|
||||
(doom-call-process "ssh " host "jupyter" "--runtime-dir")))
|
||||
(runtime-file (concat runtime-dir "/" "kernel-" session ".json"))
|
||||
(tramp-path (concat "/ssh:" host ":" runtime-file))
|
||||
(tramp-copy (concat (or +ob-ipython-local-runtime-dir
|
||||
(cdr (doom-call-process "jupyter" "--runtime-dir")))
|
||||
"/remote-" host "-kernel-" session ".json"))
|
||||
(local-path
|
||||
(concat
|
||||
"Python:ob-ipython-"
|
||||
(file-name-sans-extension (file-name-nondirectory tramp-copy))
|
||||
"-ssh.json")))
|
||||
;; scp remote file to local
|
||||
(copy-file tramp-path tramp-copy t)
|
||||
;; connect to remote use new config
|
||||
(let* ((python-shell-interpreter-interactive-arg " console --simple-prompt")
|
||||
(python-shell-prompt-detect-enabled nil)
|
||||
(python-shell-completion-native-enable nil)
|
||||
(buf (python-shell-make-comint
|
||||
(concat ob-ipython-command
|
||||
" console --simple-prompt --existing "
|
||||
tramp-copy " --ssh " host)
|
||||
(concat "" local-path)
|
||||
t))
|
||||
(proc (get-buffer-process buf))
|
||||
(dir (cdr (assoc :pydir params))))
|
||||
(sleep-for 3)
|
||||
(when dir
|
||||
(with-current-buffer buf
|
||||
(setq-local default-directory dir)))
|
||||
(format "*%s*" proc))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-ob-ipython-create-repl-a (name &optional params)
|
||||
"Create repl based on NAME and PARAMS.
|
||||
If PARAMS specifies remote kernel, copy the kernel config from remote server and
|
||||
create a repl connecting to remote session."
|
||||
(let ((cmd (string-join (ob-ipython--kernel-repl-cmd name) " ")))
|
||||
(cond ((string= "default" name)
|
||||
(run-python cmd nil nil)
|
||||
(format "*%s*" python-shell-buffer-name))
|
||||
((string-match "^remote-.*ssh.json" name)
|
||||
(when (not (ignore-errors
|
||||
(process-live-p
|
||||
(get-process
|
||||
(format
|
||||
"Python:ob-ipython-%s"
|
||||
name)))))
|
||||
(let* ((remote (s-split "-" name))
|
||||
(remote-host (nth 1 remote))
|
||||
(remote-session (nth 3 remote)))
|
||||
(+org--ob-ipython-generate-local-path-from-remote
|
||||
remote-session
|
||||
remote-host
|
||||
params))))
|
||||
((let* ((process-name (format "Python:ob-ipython-%s" name))
|
||||
(python-shell-prompt-detect-enabled nil)
|
||||
(python-shell-completion-native-enable nil)
|
||||
(buf (python-shell-make-comint cmd process-name t))
|
||||
(dir (cdr (assoc :pydir params))))
|
||||
(if dir
|
||||
(with-current-buffer buf
|
||||
(setq-local default-directory dir)))
|
||||
(sleep-for 1)
|
||||
(format "*%s*" process-name))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-babel-execute:ipython-a (body params)
|
||||
"Execute a BODY of IPython code with PARAMS in org-babel.
|
||||
This function is called by `org-babel-execute-src-block'."
|
||||
(message default-directory)
|
||||
(org-babel-ipython-initiate-session (cdr (assoc :session params))
|
||||
params))
|
||||
|
||||
|
||||
;;
|
||||
;; * org-src-edit
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-babel-edit-prep:ipython-a (info)
|
||||
(let* ((params (nth 2 info))
|
||||
(session (cdr (assoc :session params))))
|
||||
(org-babel-ipython-initiate-session session params))
|
||||
;; Support for python.el's "send-code" commands within edit buffers.
|
||||
(setq-local python-shell-buffer-name
|
||||
(format "Python:ob-ipython-%s"
|
||||
(ob-ipython--normalize-session
|
||||
(cdr (assoc :session (nth 2 info))))))
|
||||
(setq-local default-directory
|
||||
(format "%s"
|
||||
(ob-ipython--normalize-session
|
||||
(cdr (assoc :pydir (nth 2 info))))))
|
||||
(ob-ipython-mode 1)
|
||||
;; hack on company mode to use company-capf rather than company-anaconda
|
||||
(when (featurep! :completion company)
|
||||
(setq-local company-backends
|
||||
'(company-capf
|
||||
company-dabbrev
|
||||
company-files
|
||||
company-yasnippet))
|
||||
(setq-local company-idle-delay nil))
|
||||
(when (featurep 'lpy)
|
||||
(setq lispy-python-proc
|
||||
(format "Python:ob-ipython-%s"
|
||||
(ob-ipython--normalize-session
|
||||
(cdr (assoc :session (nth 2 info)))))
|
||||
lispy--python-middleware-loaded-p nil)
|
||||
(lispy--python-middleware-load)))
|
||||
|
||||
|
||||
;;
|
||||
;; * retina
|
||||
|
||||
(defun +org--ob-ipython-mac-2x-image-file-name (filename &optional scale)
|
||||
"Return the name of high-resolution image file for FILENAME.
|
||||
The optional arg SCALE is scale factor, and defaults to 2."
|
||||
(let ((pos (or (string-match "\\.[^./]*\\'" filename) (length filename))))
|
||||
(format "%s@%dx%s"
|
||||
(substring filename 0 pos)
|
||||
(or scale 2)
|
||||
(substring filename pos))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-ob-ipython-write-base64-string-a (oldfunc &rest args)
|
||||
(let ((file (car args))
|
||||
(b64-string (cdr args)))
|
||||
(let ((file2x (+org--ob-ipython-mac-2x-image-file-name file)))
|
||||
(apply oldfunc file2x b64-string)
|
||||
(shell-command (concat "convert " file2x " -resize 50% " file)))))
|
||||
85
.config/emacs/modules/lang/org/autoload/contrib-present.el
Normal file
85
.config/emacs/modules/lang/org/autoload/contrib-present.el
Normal file
@@ -0,0 +1,85 @@
|
||||
;;; lang/org/autoload/contrib-present.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +present)
|
||||
|
||||
;;
|
||||
;;; Helpers
|
||||
|
||||
(defun +org-present--cleanup-org-tree-slides-mode ()
|
||||
(unless (cl-loop for buf in (doom-buffers-in-mode 'org-mode)
|
||||
if (buffer-local-value 'org-tree-slide-mode buf)
|
||||
return t)
|
||||
(org-tree-slide-mode -1)
|
||||
(remove-hook 'kill-buffer-hook #'+org-present--cleanup-org-tree-slides-mode
|
||||
'local)))
|
||||
|
||||
|
||||
;;
|
||||
;;; Hooks
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-present-hide-blocks-h ()
|
||||
"Hide org #+ constructs."
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward "^[[:space:]]*\\(#\\+\\)\\(\\(?:BEGIN\\|END\\|ATTR\\)[^[:space:]]+\\).*" nil t)
|
||||
(org-flag-region (match-beginning 1)
|
||||
(match-end 0)
|
||||
org-tree-slide-mode
|
||||
t))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-present-hide-leading-stars-h ()
|
||||
"Hide leading stars in headings."
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward "^\\(\\*+\\)" nil t)
|
||||
(org-flag-region (match-beginning 1)
|
||||
(match-end 1)
|
||||
org-tree-slide-mode
|
||||
t))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-present-detect-slide-h ()
|
||||
"TODO"
|
||||
(outline-show-all)
|
||||
(if (member "title" (org-get-tags))
|
||||
(text-scale-set 10)
|
||||
(text-scale-set +org-present-text-scale)))
|
||||
|
||||
(defvar cwm-use-vertical-padding)
|
||||
(defvar cwm-frame-internal-border)
|
||||
(defvar cwm-left-fringe-ratio)
|
||||
(defvar cwm-centered-window-width)
|
||||
(defvar +org-present--last-wconf nil)
|
||||
;;;###autoload
|
||||
(defun +org-present-prettify-slide-h ()
|
||||
"Set up the org window for presentation."
|
||||
(let ((arg (if org-tree-slide-mode +1 -1)))
|
||||
(if (not org-tree-slide-mode)
|
||||
(when +org-present--last-wconf
|
||||
(set-window-configuration +org-present--last-wconf))
|
||||
(setq +org-present--last-wconf (current-window-configuration))
|
||||
(doom/window-maximize-buffer))
|
||||
(when (fboundp 'centered-window-mode)
|
||||
(setq-local cwm-use-vertical-padding t)
|
||||
(setq-local cwm-frame-internal-border 100)
|
||||
(setq-local cwm-left-fringe-ratio -10)
|
||||
(setq-local cwm-centered-window-width 300)
|
||||
(centered-window-mode arg))
|
||||
(hide-mode-line-mode arg)
|
||||
(+org-pretty-mode arg)
|
||||
(cond (org-tree-slide-mode
|
||||
(set-window-fringes nil 0 0)
|
||||
(when (bound-and-true-p flyspell-mode)
|
||||
(flyspell-mode -1))
|
||||
(add-hook 'kill-buffer-hook #'+org-present--cleanup-org-tree-slides-mode
|
||||
nil 'local)
|
||||
(text-scale-set +org-present-text-scale)
|
||||
(ignore-errors (org-latex-preview '(4))))
|
||||
(t
|
||||
(text-scale-set 0)
|
||||
(set-window-fringes nil fringe-mode fringe-mode)
|
||||
(org-clear-latex-preview)
|
||||
(org-remove-inline-images)
|
||||
(org-mode)))
|
||||
(redraw-display)))
|
||||
58
.config/emacs/modules/lang/org/autoload/contrib-roam2.el
Normal file
58
.config/emacs/modules/lang/org/autoload/contrib-roam2.el
Normal file
@@ -0,0 +1,58 @@
|
||||
;;; lang/org/autoload/contrib-roam2.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +roam2)
|
||||
|
||||
;;; Custom node accessors
|
||||
;;;###autoload (autoload 'org-roam-node-doom-filetitle "lang/org/autoload/contrib-roam2" nil t)
|
||||
(cl-defmethod org-roam-node-doom-filetitle ((node org-roam-node))
|
||||
"Return the value of \"#+title:\" (if any) from file that NODE resides in.
|
||||
If there's no file-level title in the file, return empty string."
|
||||
(or (if (= (org-roam-node-level node) 0)
|
||||
(org-roam-node-title node)
|
||||
(org-roam-get-keyword "TITLE" (org-roam-node-file node)))
|
||||
""))
|
||||
|
||||
;;;###autoload (autoload 'org-roam-node-doom-hierarchy "lang/org/autoload/contrib-roam2" nil t)
|
||||
(cl-defmethod org-roam-node-doom-hierarchy ((node org-roam-node))
|
||||
"Return hierarchy for NODE, constructed of its file title, OLP and direct title.
|
||||
If some elements are missing, they will be stripped out."
|
||||
(let ((title (org-roam-node-title node))
|
||||
(olp (org-roam-node-olp node))
|
||||
(level (org-roam-node-level node))
|
||||
(filetitle (org-roam-node-doom-filetitle node))
|
||||
(separator (propertize " > " 'face 'shadow)))
|
||||
(cl-case level
|
||||
;; node is a top-level file
|
||||
(0 filetitle)
|
||||
;; node is a level 1 heading
|
||||
(1 (concat (propertize filetitle 'face '(shadow italic))
|
||||
separator title))
|
||||
;; node is a heading with an arbitrary outline path
|
||||
(t (concat (propertize filetitle 'face '(shadow italic))
|
||||
separator (propertize (string-join olp " > ") 'face '(shadow italic))
|
||||
separator title)))))
|
||||
|
||||
;;;###autoload (autoload 'org-roam-node-doom-subdirs "lang/org/autoload/contrib-roam2" nil t)
|
||||
(cl-defmethod org-roam-node-doom-subdirs ((node org-roam-node))
|
||||
"Return subdirectories of `org-roam-directory' in which NODE resides in.
|
||||
If there's none, return an empty string."
|
||||
(if-let ((dirs (thread-first node
|
||||
(org-roam-node-file)
|
||||
(file-relative-name org-roam-directory)
|
||||
(file-name-directory))))
|
||||
dirs
|
||||
""))
|
||||
|
||||
;;;###autoload (autoload 'org-roam-node-doom-tags "lang/org/autoload/contrib-roam2" nil t)
|
||||
(cl-defmethod org-roam-node-doom-tags ((node org-roam-node))
|
||||
"Return tags formatted in the same way how they appear in org files.
|
||||
Treat subdirectories as tags too. If there's no elements to build
|
||||
the tags of, return an empty string."
|
||||
(let ((tags (org-roam-node-tags node))
|
||||
(subdirs (org-roam-node-doom-subdirs node)))
|
||||
(when tags
|
||||
(setq tags (propertize (concat (mapconcat (lambda (s) (concat ":" s)) tags nil) ":")
|
||||
'face 'shadow)))
|
||||
(unless (string-empty-p subdirs)
|
||||
(setq subdirs (propertize (concat ":" (replace-regexp-in-string "/\\|\\\\" ":" subdirs))
|
||||
'face '(shadow italic))))
|
||||
(replace-regexp-in-string ":+" (propertize ":" 'face 'shadow) (concat subdirs tags))))
|
||||
59
.config/emacs/modules/lang/org/autoload/org-attach.el
Normal file
59
.config/emacs/modules/lang/org/autoload/org-attach.el
Normal file
@@ -0,0 +1,59 @@
|
||||
;;; lang/org/autoload/org-attach.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-attach-icon-for (path)
|
||||
(char-to-string
|
||||
(pcase (downcase (file-name-extension path))
|
||||
((or "jpg" "jpeg" "png" "gif") ?)
|
||||
("pdf" ?)
|
||||
((or "ppt" "pptx") ?)
|
||||
((or "xls" "xlsx") ?)
|
||||
((or "doc" "docx") ?)
|
||||
((or "ogg" "mp3" "wav" "aiff" "flac") ?)
|
||||
((or "mp4" "mov" "avi") ?)
|
||||
((or "zip" "gz" "tar" "7z" "rar") ?)
|
||||
(_ ?))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/open-gallery-from-attachments ()
|
||||
"TODO"
|
||||
(interactive)
|
||||
(require 'org-attach)
|
||||
(if-let (dir (org-attach-dir))
|
||||
(pop-to-buffer
|
||||
;; Rather than opening dired *and* image-dired windows, suppress them
|
||||
;; both and open only the image-dired window.
|
||||
(save-window-excursion
|
||||
(image-dired dir)
|
||||
(current-buffer)))
|
||||
(user-error "No attachments for this node")))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/find-file-in-attachments ()
|
||||
"Open a file from `org-attach-id-dir'."
|
||||
(interactive)
|
||||
(doom-project-browse org-attach-id-dir))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/attach-file-and-insert-link (path)
|
||||
"Downloads the file at PATH and insert an org link at point.
|
||||
PATH (a string) can be an url, a local file path, or a base64 encoded datauri."
|
||||
(interactive "sUri/file: ")
|
||||
(unless (eq major-mode 'org-mode)
|
||||
(user-error "Not in an org buffer"))
|
||||
(require 'org-download)
|
||||
(condition-case-unless-debug e
|
||||
(let ((raw-uri (url-unhex-string path)))
|
||||
(cond ((string-match-p "^data:image/png;base64," path)
|
||||
(org-download-dnd-base64 path nil))
|
||||
((image-type-from-file-name raw-uri)
|
||||
(org-download-image raw-uri))
|
||||
((let ((new-path (expand-file-name (org-download--fullname raw-uri))))
|
||||
;; Download the file
|
||||
(if (string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) ":/") path)
|
||||
(url-copy-file raw-uri new-path)
|
||||
(copy-file path new-path))
|
||||
;; insert the link
|
||||
(org-download-insert-link raw-uri new-path)))))
|
||||
(error
|
||||
(user-error "Failed to attach file: %s" (error-message-string e)))))
|
||||
20
.config/emacs/modules/lang/org/autoload/org-avy.el
Normal file
20
.config/emacs/modules/lang/org/autoload/org-avy.el
Normal file
@@ -0,0 +1,20 @@
|
||||
;;; lang/org/autoload/org-avy.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-headline-avy ()
|
||||
"TODO"
|
||||
(require 'avy)
|
||||
(save-excursion
|
||||
(when-let* ((org-reverse-note-order t)
|
||||
(pos (avy-with avy-goto-line (avy-jump (rx bol (1+ "*") (1+ blank))))))
|
||||
(when (integerp (car pos))
|
||||
;; If avy is aborted with "C-g", it returns `t', so we know it was NOT
|
||||
;; aborted when it returns an int. If it doesn't return an int, we
|
||||
;; return nil.
|
||||
(copy-marker (car pos))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/goto-visible ()
|
||||
"TODO"
|
||||
(interactive)
|
||||
(goto-char (+org-headline-avy)))
|
||||
78
.config/emacs/modules/lang/org/autoload/org-babel.el
Normal file
78
.config/emacs/modules/lang/org/autoload/org-babel.el
Normal file
@@ -0,0 +1,78 @@
|
||||
;;; lang/org/autoload/org-babel.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-eval-handler (beg end)
|
||||
"TODO"
|
||||
(save-excursion
|
||||
(if (not (cl-loop for pos in (list beg (point) end)
|
||||
if (save-excursion (goto-char pos) (org-in-src-block-p t))
|
||||
return (goto-char pos)))
|
||||
(message "Nothing to evaluate at point")
|
||||
(let* ((element (org-element-at-point))
|
||||
(block-beg (save-excursion
|
||||
(goto-char (org-babel-where-is-src-block-head element))
|
||||
(line-beginning-position 2)))
|
||||
(block-end (save-excursion
|
||||
(goto-char (org-element-property :end element))
|
||||
(skip-chars-backward " \t\n")
|
||||
(line-beginning-position)))
|
||||
(beg (if beg (max beg block-beg) block-beg))
|
||||
(end (if end (min end block-end) block-end))
|
||||
(lang (or (org-eldoc-get-src-lang)
|
||||
(user-error "No lang specified for this src block"))))
|
||||
(cond ((and (string-prefix-p "jupyter-" lang)
|
||||
(require 'jupyter nil t))
|
||||
(jupyter-eval-region beg end))
|
||||
((let ((major-mode (org-src-get-lang-mode lang)))
|
||||
(+eval/region beg end))))))))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-lookup-definition-handler (identifier)
|
||||
"TODO"
|
||||
(when (org-in-src-block-p t)
|
||||
(let ((mode (org-src-get-lang-mode
|
||||
(or (org-eldoc-get-src-lang)
|
||||
(user-error "No lang specified for this src block")))))
|
||||
(cond ((and (eq mode 'emacs-lisp-mode)
|
||||
(fboundp '+emacs-lisp-lookup-definition))
|
||||
(+emacs-lisp-lookup-definition identifier)
|
||||
'deferred)
|
||||
((user-error "Definition lookup in SRC blocks isn't supported yet"))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-lookup-references-handler (identifier)
|
||||
"TODO"
|
||||
(when (org-in-src-block-p t)
|
||||
(user-error "References lookup in SRC blocks isn't supported yet")))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-lookup-documentation-handler (identifier)
|
||||
"TODO"
|
||||
(when (org-in-src-block-p t)
|
||||
(let ((mode (org-src-get-lang-mode
|
||||
(or (org-eldoc-get-src-lang)
|
||||
(user-error "No lang specified for this src block"))))
|
||||
(info (org-babel-get-src-block-info t)))
|
||||
(cond ((string-prefix-p "jupyter-" (car info))
|
||||
(and (require 'jupyter nil t)
|
||||
(call-interactively #'jupyter-inspect-at-point)
|
||||
(display-buffer (help-buffer))
|
||||
'deferred))
|
||||
((and (eq mode 'emacs-lisp-mode)
|
||||
(fboundp '+emacs-lisp-lookup-documentation))
|
||||
(+emacs-lisp-lookup-documentation identifier)
|
||||
'deferred)
|
||||
((user-error "Documentation lookup in SRC blocks isn't supported yet"))))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Hooks
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-clear-babel-results-h ()
|
||||
"Remove the results block for the org babel block at point."
|
||||
(when (and (org-in-src-block-p t)
|
||||
(org-babel-where-is-src-block-result))
|
||||
(org-babel-remove-result)
|
||||
t))
|
||||
161
.config/emacs/modules/lang/org/autoload/org-capture.el
Normal file
161
.config/emacs/modules/lang/org/autoload/org-capture.el
Normal file
@@ -0,0 +1,161 @@
|
||||
;;; lang/org/autoload/org-capture.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar org-capture-initial)
|
||||
|
||||
|
||||
;;
|
||||
;;; External frame
|
||||
|
||||
(defvar +org-capture-fn #'org-capture
|
||||
"Command to use to initiate org-capture.")
|
||||
|
||||
;;;###autoload
|
||||
(defvar +org-capture-frame-parameters
|
||||
`((name . "doom-capture")
|
||||
(width . 70)
|
||||
(height . 25)
|
||||
(transient . t)
|
||||
,@(when IS-LINUX
|
||||
`((window-system . ,(if (boundp 'pgtk-initialized) 'pgtk 'x))
|
||||
(display . ,(or (getenv "DISPLAY") ":0"))))
|
||||
,(if IS-MAC '(menu-bar-lines . 1)))
|
||||
"TODO")
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture-cleanup-frame-h ()
|
||||
"Closes the org-capture frame once done adding an entry."
|
||||
(when (and (+org-capture-frame-p)
|
||||
(not org-capture-is-refiling))
|
||||
(delete-frame nil t)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture-frame-p (&rest _)
|
||||
"Return t if the current frame is an org-capture frame opened by
|
||||
`+org-capture/open-frame'."
|
||||
(and (equal (alist-get 'name +org-capture-frame-parameters)
|
||||
(frame-parameter nil 'name))
|
||||
(frame-parameter nil 'transient)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture/open-frame (&optional initial-input key)
|
||||
"Opens the org-capture window in a floating frame that cleans itself up once
|
||||
you're done. This can be called from an external shell script."
|
||||
(interactive)
|
||||
(when (and initial-input (string-empty-p initial-input))
|
||||
(setq initial-input nil))
|
||||
(when (and key (string-empty-p key))
|
||||
(setq key nil))
|
||||
(let* ((frame-title-format "")
|
||||
(frame (if (+org-capture-frame-p)
|
||||
(selected-frame)
|
||||
(make-frame +org-capture-frame-parameters))))
|
||||
(select-frame-set-input-focus frame) ; fix MacOS not focusing new frames
|
||||
(with-selected-frame frame
|
||||
(require 'org-capture)
|
||||
(condition-case ex
|
||||
(letf! ((#'pop-to-buffer #'switch-to-buffer))
|
||||
(switch-to-buffer (doom-fallback-buffer))
|
||||
(let ((org-capture-initial initial-input)
|
||||
org-capture-entry)
|
||||
(when (and key (not (string-empty-p key)))
|
||||
(setq org-capture-entry (org-capture-select-template key)))
|
||||
(funcall +org-capture-fn)))
|
||||
('error
|
||||
(message "org-capture: %s" (error-message-string ex))
|
||||
(delete-frame frame))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture-available-keys ()
|
||||
"TODO"
|
||||
(string-join (mapcar #'car org-capture-templates) ""))
|
||||
|
||||
|
||||
;;
|
||||
;;; Capture targets
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture-todo-file ()
|
||||
"Expand `+org-capture-todo-file' from `org-directory'.
|
||||
If it is an absolute path return `+org-capture-todo-file' verbatim."
|
||||
(expand-file-name +org-capture-todo-file org-directory))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture-notes-file ()
|
||||
"Expand `+org-capture-notes-file' from `org-directory'.
|
||||
If it is an absolute path return `+org-capture-todo-file' verbatim."
|
||||
(expand-file-name +org-capture-notes-file org-directory))
|
||||
|
||||
(defun +org--capture-local-root (path)
|
||||
(let ((filename (file-name-nondirectory path)))
|
||||
(expand-file-name
|
||||
filename
|
||||
(or (locate-dominating-file (file-truename default-directory)
|
||||
filename)
|
||||
(doom-project-root)
|
||||
(user-error "Couldn't detect a project")))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture-project-todo-file ()
|
||||
"Find the nearest `+org-capture-todo-file' in a parent directory, otherwise,
|
||||
opens a blank one at the project root. Throws an error if not in a project."
|
||||
(+org--capture-local-root +org-capture-todo-file))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture-project-notes-file ()
|
||||
"Find the nearest `+org-capture-notes-file' in a parent directory, otherwise,
|
||||
opens a blank one at the project root. Throws an error if not in a project."
|
||||
(+org--capture-local-root +org-capture-notes-file))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture-project-changelog-file ()
|
||||
"Find the nearest `+org-capture-changelog-file' in a parent directory,
|
||||
otherwise, opens a blank one at the project root. Throws an error if not in a
|
||||
project."
|
||||
(+org--capture-local-root +org-capture-changelog-file))
|
||||
|
||||
(defun +org--capture-ensure-heading (headings &optional initial-level)
|
||||
(if (not headings)
|
||||
(widen)
|
||||
(let ((initial-level (or initial-level 1)))
|
||||
(if (and (re-search-forward (format org-complex-heading-regexp-format
|
||||
(regexp-quote (car headings)))
|
||||
nil t)
|
||||
(= (org-current-level) initial-level))
|
||||
(progn
|
||||
(beginning-of-line)
|
||||
(org-narrow-to-subtree))
|
||||
(goto-char (point-max))
|
||||
(unless (and (bolp) (eolp)) (insert "\n"))
|
||||
(insert (make-string initial-level ?*)
|
||||
" " (car headings) "\n")
|
||||
(beginning-of-line 0))
|
||||
(+org--capture-ensure-heading (cdr headings) (1+ initial-level)))))
|
||||
|
||||
(defun +org--capture-central-file (file project)
|
||||
(let ((file (expand-file-name file org-directory)))
|
||||
(set-buffer (org-capture-target-buffer file))
|
||||
(org-capture-put-target-region-and-position)
|
||||
(widen)
|
||||
(goto-char (point-min))
|
||||
;; Find or create the project headling
|
||||
(+org--capture-ensure-heading
|
||||
(append (org-capture-get :parents)
|
||||
(list project (org-capture-get :heading))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture-central-project-todo-file ()
|
||||
"TODO"
|
||||
(+org--capture-central-file
|
||||
+org-capture-projects-file (projectile-project-name)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture-central-project-notes-file ()
|
||||
"TODO"
|
||||
(+org--capture-central-file
|
||||
+org-capture-projects-file (projectile-project-name)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-capture-central-project-changelog-file ()
|
||||
"TODO"
|
||||
(+org--capture-central-file
|
||||
+org-capture-projects-file (projectile-project-name)))
|
||||
53
.config/emacs/modules/lang/org/autoload/org-export.el
Normal file
53
.config/emacs/modules/lang/org/autoload/org-export.el
Normal file
@@ -0,0 +1,53 @@
|
||||
;;; lang/org/autoload/org-export.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defun +org--yank-html-buffer (buffer)
|
||||
(with-current-buffer buffer
|
||||
(require 'ox-clip)
|
||||
(cond ((or IS-WINDOWS IS-MAC)
|
||||
(shell-command-on-region
|
||||
(point-min)
|
||||
(point-max)
|
||||
(cond (IS-WINDOWS ox-clip-w32-cmd)
|
||||
(IS-MAC ox-clip-osx-cmd))))
|
||||
(IS-LINUX
|
||||
(let ((html (buffer-string)))
|
||||
(with-temp-file (make-temp-file "ox-clip-md" nil ".html")
|
||||
(insert html))
|
||||
(apply #'start-process "ox-clip" "*ox-clip*"
|
||||
(split-string ox-clip-linux-cmd " ")))))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Commands
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/export-to-clipboard (backend)
|
||||
"Exports the current buffer/selection to the clipboard.
|
||||
|
||||
Prompts for what BACKEND to use. See `org-export-backends' for options."
|
||||
(interactive
|
||||
(list (intern (completing-read "Export to: " (progn (require 'ox) org-export-backends)))))
|
||||
(require 'ox)
|
||||
(let* ((org-export-show-temporary-export-buffer nil)
|
||||
(buffer (org-export-to-buffer backend "*Formatted Copy*" nil nil t t)))
|
||||
(unwind-protect
|
||||
(with-current-buffer buffer
|
||||
(kill-new (buffer-string)))
|
||||
(kill-buffer buffer))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/export-to-clipboard-as-rich-text (beg end)
|
||||
"Export the current buffer to HTML then copies it to clipboard as rich text.
|
||||
|
||||
Supports org-mode, markdown-mode, and gfm-mode buffers. In any other mode,
|
||||
htmlize is used (takes what you see in Emacs and converts it to html, text
|
||||
properties and font-locking et all)."
|
||||
(interactive "r")
|
||||
(pcase major-mode
|
||||
((or `markdown-mode `gfm-mode)
|
||||
(+org--yank-html-buffer (markdown)))
|
||||
(_
|
||||
;; Omit after/before-string overlay properties in htmlized regions, so we
|
||||
;; don't get fringe characters for things like flycheck or git-gutter.
|
||||
(letf! (defun htmlize-add-before-after-strings (_beg _end text) text)
|
||||
(ox-clip-formatted-copy beg end)))))
|
||||
248
.config/emacs/modules/lang/org/autoload/org-link.el
Normal file
248
.config/emacs/modules/lang/org/autoload/org-link.el
Normal file
@@ -0,0 +1,248 @@
|
||||
;;; lang/org/autoload/org-link.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defun +org--relative-path (path root)
|
||||
(if (and buffer-file-name (file-in-directory-p buffer-file-name root))
|
||||
(file-relative-name path)
|
||||
path))
|
||||
|
||||
(defun +org--read-link-path (key dir &optional fn)
|
||||
(let ((file (funcall (or fn #'read-file-name) (format "%s: " (capitalize key)) dir)))
|
||||
(format "%s:%s" key (file-relative-name file dir))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-read-link-description-at-point (&optional default context)
|
||||
"TODO"
|
||||
(if (and (stringp default) (not (string-empty-p default)))
|
||||
(string-trim default)
|
||||
(if-let* ((context (or context (org-element-context)))
|
||||
(context (org-element-lineage context '(link) t))
|
||||
(beg (org-element-property :contents-begin context))
|
||||
(end (org-element-property :contents-end context)))
|
||||
(unless (= beg end)
|
||||
(replace-regexp-in-string
|
||||
"[ \n]+" " " (string-trim (buffer-substring-no-properties beg end)))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-define-basic-link (key dir-var &rest plist)
|
||||
"Define a link with some basic completion & fontification.
|
||||
|
||||
KEY is the name of the link type. DIR-VAR is the directory variable to resolve
|
||||
links relative to. PLIST is passed to `org-link-set-parameters' verbatim.
|
||||
|
||||
Links defined with this will be rendered in the `error' face if the file doesn't
|
||||
exist, and `org-link' otherwise."
|
||||
(declare (indent 2))
|
||||
(let ((requires (plist-get plist :requires))
|
||||
(dir-fn (if (functionp dir-var)
|
||||
dir-var
|
||||
(lambda () (symbol-value dir-var)))))
|
||||
(apply #'org-link-set-parameters
|
||||
key
|
||||
:complete (lambda ()
|
||||
(if requires (mapc #'require (doom-enlist requires)))
|
||||
(+org--relative-path (+org--read-link-path key (funcall dir-fn))
|
||||
(funcall dir-fn)))
|
||||
:follow (lambda (link)
|
||||
(org-link-open-as-file (expand-file-name link (funcall dir-fn)) nil))
|
||||
:face (lambda (link)
|
||||
(let* ((path (expand-file-name link (funcall dir-fn)))
|
||||
(option-index (string-match-p "::\\(.*\\)\\'" path))
|
||||
(file-name (substring path 0 option-index)))
|
||||
(if (file-exists-p file-name)
|
||||
'org-link
|
||||
'error)))
|
||||
(doom-plist-delete plist :requires))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Image data functions (for custom inline images)
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-image-file-data-fn (protocol link _description)
|
||||
"Intepret LINK as an image file path and return its data."
|
||||
(setq
|
||||
link (expand-file-name
|
||||
link (pcase protocol
|
||||
("download"
|
||||
(or (if (require 'org-download nil t) org-download-image-dir)
|
||||
(if (require 'org-attach) org-attach-id-dir)
|
||||
default-directory))
|
||||
("attachment"
|
||||
(require 'org-attach)
|
||||
org-attach-id-dir)
|
||||
(_ default-directory))))
|
||||
(when (and (file-exists-p link)
|
||||
(image-type-from-file-name link))
|
||||
(with-temp-buffer
|
||||
(set-buffer-multibyte nil)
|
||||
(setq buffer-file-coding-system 'binary)
|
||||
(insert-file-contents-literally link)
|
||||
(buffer-substring-no-properties (point-min) (point-max)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-inline-image-data-fn (_protocol link _description)
|
||||
"Interpret LINK as base64-encoded image data."
|
||||
(base64-decode-string link))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-http-image-data-fn (protocol link _description)
|
||||
"Interpret LINK as an URL to an image file."
|
||||
(when (and (image-type-from-file-name link)
|
||||
(not (eq org-display-remote-inline-images 'skip)))
|
||||
(if-let (buf (url-retrieve-synchronously (concat protocol ":" link)))
|
||||
(with-current-buffer buf
|
||||
(goto-char (point-min))
|
||||
(re-search-forward "\r?\n\r?\n" nil t)
|
||||
(buffer-substring-no-properties (point) (point-max)))
|
||||
(message "Download of image \"%s\" failed" link)
|
||||
nil)))
|
||||
|
||||
(defvar +org--gif-timers nil)
|
||||
;;;###autoload
|
||||
(defun +org-play-gif-at-point-h ()
|
||||
"Play the gif at point, while the cursor remains there (looping)."
|
||||
(dolist (timer +org--gif-timers (setq +org--gif-timers nil))
|
||||
(when (timerp (cdr timer))
|
||||
(cancel-timer (cdr timer)))
|
||||
(image-animate (car timer) nil 0))
|
||||
(when-let* ((ov (cl-find-if
|
||||
(lambda (it) (overlay-get it 'org-image-overlay))
|
||||
(overlays-at (point))))
|
||||
(dov (overlay-get ov 'display))
|
||||
(pt (point)))
|
||||
(when (image-animated-p dov)
|
||||
(push (cons
|
||||
dov (run-with-idle-timer
|
||||
0.5 nil
|
||||
(lambda (dov)
|
||||
(when (equal
|
||||
ov (cl-find-if
|
||||
(lambda (it) (overlay-get it 'org-image-overlay))
|
||||
(overlays-at (point))))
|
||||
(message "playing gif")
|
||||
(image-animate dov nil t)))
|
||||
dov))
|
||||
+org--gif-timers))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-play-all-gifs-h ()
|
||||
"Continuously play all gifs in the visible buffer."
|
||||
(dolist (ov (overlays-in (point-min) (point-max)))
|
||||
(when-let* (((overlay-get ov 'org-image-overlay))
|
||||
(dov (overlay-get ov 'display))
|
||||
((image-animated-p dov))
|
||||
(w (selected-window)))
|
||||
(while-no-input
|
||||
(run-with-idle-timer
|
||||
0.3 nil
|
||||
(lambda (dov)
|
||||
(when (pos-visible-in-window-p (overlay-start ov) w nil)
|
||||
(unless (plist-get (cdr dov) :animate-buffer)
|
||||
(image-animate dov))))
|
||||
dov)))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Commands
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/remove-link ()
|
||||
"Unlink the text at point."
|
||||
(interactive)
|
||||
(unless (org-in-regexp org-link-bracket-re 1)
|
||||
(user-error "No link at point"))
|
||||
(save-excursion
|
||||
(let ((label (if (match-end 2)
|
||||
(match-string-no-properties 2)
|
||||
(org-link-unescape (match-string-no-properties 1)))))
|
||||
(delete-region (match-beginning 0) (match-end 0))
|
||||
(insert label))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/play-gif-at-point ()
|
||||
"TODO"
|
||||
(interactive)
|
||||
(unless (eq 'org-mode major-mode)
|
||||
(user-error "Not in org-mode"))
|
||||
(or (+org-play-gif-at-point-h)
|
||||
(user-error "No gif at point")))
|
||||
|
||||
|
||||
;;
|
||||
;;; Org-link parameters
|
||||
|
||||
;;; doom-module:
|
||||
(defun +org-link--doom-module--read-link (link)
|
||||
(cl-destructuring-bind (category &optional module flag)
|
||||
(let ((desc (+org-read-link-description-at-point link)))
|
||||
(if (string-prefix-p "+" (string-trim-left desc))
|
||||
(list nil nil (intern desc))
|
||||
(mapcar #'intern (split-string desc " " nil))))
|
||||
(list :category category
|
||||
:module module
|
||||
:flag flag)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-link--doom-module-follow-fn (link)
|
||||
(cl-destructuring-bind (&key category module flag)
|
||||
(+org-link--doom-module--read-link link)
|
||||
(when category
|
||||
(let ((doom-modules-dirs (list doom-modules-dir)))
|
||||
(if-let* ((path (doom-module-locate-path category module))
|
||||
(path (or (car (doom-glob path "README.org"))
|
||||
path)))
|
||||
(find-file path)
|
||||
(user-error "Can't find Doom module '%s'" link))))
|
||||
(when flag
|
||||
(goto-char (point-min))
|
||||
(and (re-search-forward "^\\*+ \\(?:TODO \\)?Module Flags")
|
||||
(re-search-forward (format "^\\s-*- %s :: "
|
||||
(regexp-quote (symbol-name flag)))
|
||||
(save-excursion (org-get-next-sibling)
|
||||
(point)))
|
||||
(recenter)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-link--doom-module-face-fn (link)
|
||||
(cl-destructuring-bind (&key category module flag)
|
||||
(+org-link--doom-module--read-link link)
|
||||
(if (doom-module-locate-path category module)
|
||||
`(:inherit org-priority
|
||||
:weight bold)
|
||||
'error)))
|
||||
|
||||
|
||||
;;; doom-package:
|
||||
;;;###autoload
|
||||
(defun +org-link--doom-package-follow-fn (link)
|
||||
"TODO"
|
||||
(doom/describe-package
|
||||
(intern-soft
|
||||
(+org-read-link-description-at-point link))))
|
||||
|
||||
|
||||
;;; kbd:
|
||||
|
||||
(defun +org--describe-kbd (keystr)
|
||||
(dolist (key `(("<leader>" . ,doom-leader-key)
|
||||
("<localleader>" . ,doom-localleader-key)
|
||||
("<prefix>" . ,(if (bound-and-true-p evil-mode)
|
||||
(concat doom-leader-key " u")
|
||||
"C-u"))
|
||||
("<help>" . ,(if (bound-and-true-p evil-mode)
|
||||
(concat doom-leader-key " h")
|
||||
"C-h"))
|
||||
("\\<M-" . "alt-")
|
||||
("\\<S-" . "shift-")
|
||||
("\\<s-" . "super-")
|
||||
("\\<C-" . "ctrl-")))
|
||||
(setq keystr
|
||||
(replace-regexp-in-string (car key) (cdr key)
|
||||
keystr t t)))
|
||||
keystr)
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-read-kbd-at-point (&optional default context)
|
||||
"TODO"
|
||||
(+org--describe-kbd
|
||||
(+org-read-link-description-at-point default context)))
|
||||
101
.config/emacs/modules/lang/org/autoload/org-refile.el
Normal file
101
.config/emacs/modules/lang/org/autoload/org-refile.el
Normal file
@@ -0,0 +1,101 @@
|
||||
;;; lang/org/autoload/org-refile.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; REVIEW These are all proof-of-concept. Refactor me!
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/refile-to-current-file (arg &optional file)
|
||||
"Refile current heading to elsewhere in the current buffer.
|
||||
If prefix ARG, copy instead of move."
|
||||
(interactive "P")
|
||||
(let ((org-refile-targets `((,file :maxlevel . 10)))
|
||||
(org-refile-use-outline-path t)
|
||||
(org-refile-keep arg)
|
||||
current-prefix-arg)
|
||||
(call-interactively #'org-refile)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/refile-to-file (arg file)
|
||||
"Refile current heading to a particular org file.
|
||||
If prefix ARG, copy instead of move."
|
||||
(interactive
|
||||
(list current-prefix-arg
|
||||
(read-file-name "Select file to refile to: "
|
||||
default-directory
|
||||
(buffer-file-name (buffer-base-buffer))
|
||||
t nil
|
||||
(lambda (f) (string-match-p "\\.org$" f)))))
|
||||
(+org/refile-to-current-file arg file))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/refile-to-other-window (arg)
|
||||
"Refile current heading to an org buffer visible in another window.
|
||||
If prefix ARG, copy instead of move."
|
||||
(interactive "P")
|
||||
(let ((org-refile-keep arg)
|
||||
org-refile-targets
|
||||
current-prefix-arg)
|
||||
(dolist (win (delq (selected-window) (window-list)))
|
||||
(with-selected-window win
|
||||
(let ((file (buffer-file-name (buffer-base-buffer))))
|
||||
(and (eq major-mode 'org-mode)
|
||||
file
|
||||
(cl-pushnew (cons file (cons :maxlevel 10))
|
||||
org-refile-targets)))))
|
||||
(call-interactively #'org-refile)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/refile-to-other-buffer (arg)
|
||||
"Refile current heading to another, living org buffer.
|
||||
If prefix ARG, copy instead of move."
|
||||
(interactive "P")
|
||||
(let ((org-refile-keep arg)
|
||||
org-refile-targets
|
||||
current-prefix-arg)
|
||||
(dolist (buf (delq (current-buffer) (doom-buffers-in-mode 'org-mode)))
|
||||
(when-let (file (buffer-file-name (buffer-base-buffer buf)))
|
||||
(cl-pushnew (cons file (cons :maxlevel 10))
|
||||
org-refile-targets)))
|
||||
(call-interactively #'org-refile)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/refile-to-running-clock (arg)
|
||||
"Refile current heading to the currently clocked in task.
|
||||
If prefix ARG, copy instead of move."
|
||||
(interactive "P")
|
||||
(unless (bound-and-true-p org-clock-current-task)
|
||||
(user-error "No active clock to refile to"))
|
||||
(let ((org-refile-keep arg))
|
||||
(org-refile 2)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/refile-to-last-location (arg)
|
||||
"Refile current heading to the last node you refiled to.
|
||||
If prefix ARG, copy instead of move."
|
||||
(interactive "P")
|
||||
(or (assoc (plist-get org-bookmark-names-plist :last-refile)
|
||||
bookmark-alist)
|
||||
(user-error "No saved location to refile to"))
|
||||
(let ((org-refile-keep arg)
|
||||
(completing-read-function
|
||||
(lambda (_p _coll _pred _rm _ii _h default &rest _)
|
||||
default)))
|
||||
(org-refile)))
|
||||
|
||||
(defvar org-after-refile-insert-hook)
|
||||
;; Inspired by org-teleport and alphapapa/alpha-org
|
||||
;;;###autoload
|
||||
(defun +org/refile-to-visible ()
|
||||
"Refile current heading as first child of visible heading selected with Avy."
|
||||
(interactive)
|
||||
(when-let (marker (+org-headline-avy))
|
||||
(let* ((buffer (marker-buffer marker))
|
||||
(filename
|
||||
(buffer-file-name (or (buffer-base-buffer buffer)
|
||||
buffer)))
|
||||
(heading
|
||||
(org-with-point-at marker
|
||||
(org-get-heading 'no-tags 'no-todo)))
|
||||
;; Won't work with target buffers whose filename is nil
|
||||
(rfloc (list heading filename nil marker))
|
||||
(org-after-refile-insert-hook (cons #'org-reveal org-after-refile-insert-hook)))
|
||||
(org-refile nil nil rfloc))))
|
||||
96
.config/emacs/modules/lang/org/autoload/org-tables.el
Normal file
96
.config/emacs/modules/lang/org/autoload/org-tables.el
Normal file
@@ -0,0 +1,96 @@
|
||||
;;; lang/org/autoload/org-tables.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;
|
||||
;;; Row/Column traversal
|
||||
|
||||
;;;###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)
|
||||
(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))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Row/Column insertion
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/table-insert-column-left ()
|
||||
"Insert a new column left of the current column."
|
||||
(interactive)
|
||||
(org-table-insert-column)
|
||||
(org-table-move-column-left))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/table-insert-row-below ()
|
||||
"Insert a new row below the current row."
|
||||
(interactive)
|
||||
(org-table-insert-row 'below))
|
||||
|
||||
|
||||
;;
|
||||
;;; Hooks
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-realign-table-maybe-h ()
|
||||
"Auto-align table under cursor."
|
||||
(when (and (org-at-table-p) org-table-may-need-update)
|
||||
(let ((pt (point))
|
||||
(inhibit-message t))
|
||||
(if org-table-may-need-update (org-table-align))
|
||||
(goto-char pt))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-enable-auto-reformat-tables-h ()
|
||||
"Realign tables & update formulas when exiting insert mode (`evil-mode').
|
||||
Meant for `org-mode-hook'."
|
||||
(when (featurep 'evil)
|
||||
(add-hook 'evil-insert-state-exit-hook #'+org-realign-table-maybe-h nil t)
|
||||
(add-hook 'evil-replace-state-exit-hook #'+org-realign-table-maybe-h nil t)
|
||||
(advice-add #'evil-replace :after #'+org-realign-table-maybe-a)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-delete-backward-char-and-realign-table-maybe-h ()
|
||||
"Ensure deleting characters with backspace doesn't deform the table cell."
|
||||
(when (eq major-mode 'org-mode)
|
||||
(org-check-before-invisible-edit 'delete-backward)
|
||||
(save-match-data
|
||||
(when (and (org-at-table-p)
|
||||
(not (org-region-active-p))
|
||||
(string-match-p "|" (buffer-substring (point-at-bol) (point)))
|
||||
(looking-at-p ".*?|"))
|
||||
(let ((pos (point))
|
||||
(noalign (looking-at-p "[^|\n\r]* |"))
|
||||
(c org-table-may-need-update))
|
||||
(delete-char -1)
|
||||
(unless overwrite-mode
|
||||
(skip-chars-forward "^|")
|
||||
(insert " ")
|
||||
(goto-char (1- pos)))
|
||||
;; noalign: if there were two spaces at the end, this field
|
||||
;; does not determine the width of the column.
|
||||
(when noalign (setq org-table-may-need-update c)))
|
||||
t))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Advice
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-realign-table-maybe-a (&rest _)
|
||||
"Auto-align table under cursor and re-calculate formulas."
|
||||
(when (eq major-mode 'org-mode)
|
||||
(+org-realign-table-maybe-h)))
|
||||
487
.config/emacs/modules/lang/org/autoload/org.el
Normal file
487
.config/emacs/modules/lang/org/autoload/org.el
Normal file
@@ -0,0 +1,487 @@
|
||||
;;; lang/org/autoload/org.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;
|
||||
;;; Helpers
|
||||
|
||||
(defun +org--toggle-inline-images-in-subtree (&optional beg end refresh)
|
||||
"Refresh inline image previews in the current heading/tree."
|
||||
(let ((beg (or beg
|
||||
(if (org-before-first-heading-p)
|
||||
(line-beginning-position)
|
||||
(save-excursion (org-back-to-heading) (point)))))
|
||||
(end (or end
|
||||
(if (org-before-first-heading-p)
|
||||
(line-end-position)
|
||||
(save-excursion (org-end-of-subtree) (point)))))
|
||||
(overlays (cl-remove-if-not (lambda (ov) (overlay-get ov 'org-image-overlay))
|
||||
(ignore-errors (overlays-in beg end)))))
|
||||
(dolist (ov overlays nil)
|
||||
(delete-overlay ov)
|
||||
(setq org-inline-image-overlays (delete ov org-inline-image-overlays)))
|
||||
(when (or refresh (not overlays))
|
||||
(org-display-inline-images t t beg end)
|
||||
t)))
|
||||
|
||||
(defun +org--insert-item (direction)
|
||||
(let ((context (org-element-lineage
|
||||
(org-element-context)
|
||||
'(table table-row headline inlinetask item plain-list)
|
||||
t)))
|
||||
(pcase (org-element-type context)
|
||||
;; Add a new list item (carrying over checkboxes if necessary)
|
||||
((or `item `plain-list)
|
||||
;; Position determines where org-insert-todo-heading and org-insert-item
|
||||
;; insert the new list item.
|
||||
(if (eq direction 'above)
|
||||
(org-beginning-of-item)
|
||||
(org-end-of-item)
|
||||
(backward-char))
|
||||
(org-insert-item (org-element-property :checkbox context))
|
||||
;; Handle edge case where current item is empty and bottom of list is
|
||||
;; flush against a new heading.
|
||||
(when (and (eq direction 'below)
|
||||
(eq (org-element-property :contents-begin context)
|
||||
(org-element-property :contents-end context)))
|
||||
(org-end-of-item)
|
||||
(org-end-of-line)))
|
||||
|
||||
;; Add a new table row
|
||||
((or `table `table-row)
|
||||
(pcase direction
|
||||
('below (save-excursion (org-table-insert-row t))
|
||||
(org-table-next-row))
|
||||
('above (save-excursion (org-shiftmetadown))
|
||||
(+org/table-previous-row))))
|
||||
|
||||
;; Otherwise, add a new heading, carrying over any todo state, if
|
||||
;; necessary.
|
||||
(_
|
||||
(let ((level (or (org-current-level) 1)))
|
||||
;; I intentionally avoid `org-insert-heading' and the like because they
|
||||
;; impose unpredictable whitespace rules depending on the cursor
|
||||
;; position. It's simpler to express this command's responsibility at a
|
||||
;; lower level than work around all the quirks in org's API.
|
||||
(pcase direction
|
||||
(`below
|
||||
(let (org-insert-heading-respect-content)
|
||||
(goto-char (line-end-position))
|
||||
(org-end-of-subtree)
|
||||
(insert "\n" (make-string level ?*) " ")))
|
||||
(`above
|
||||
(org-back-to-heading)
|
||||
(insert (make-string level ?*) " ")
|
||||
(save-excursion (insert "\n"))))
|
||||
(when-let* ((todo-keyword (org-element-property :todo-keyword context))
|
||||
(todo-type (org-element-property :todo-type context)))
|
||||
(org-todo
|
||||
(cond ((eq todo-type 'done)
|
||||
;; Doesn't make sense to create more "DONE" headings
|
||||
(car (+org-get-todo-keywords-for todo-keyword)))
|
||||
(todo-keyword)
|
||||
('todo)))))))
|
||||
|
||||
(when (org-invisible-p)
|
||||
(org-show-hidden-entry))
|
||||
(when (and (bound-and-true-p evil-local-mode)
|
||||
(not (evil-emacs-state-p)))
|
||||
(evil-insert 1))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-get-todo-keywords-for (&optional keyword)
|
||||
"Returns the list of todo keywords that KEYWORD belongs to."
|
||||
(when keyword
|
||||
(cl-loop for (type . keyword-spec)
|
||||
in (cl-remove-if-not #'listp org-todo-keywords)
|
||||
for keywords =
|
||||
(mapcar (lambda (x) (if (string-match "^\\([^(]+\\)(" x)
|
||||
(match-string 1 x)
|
||||
x))
|
||||
keyword-spec)
|
||||
if (eq type 'sequence)
|
||||
if (member keyword keywords)
|
||||
return keywords)))
|
||||
|
||||
|
||||
;;
|
||||
;;; Modes
|
||||
|
||||
;;;###autoload
|
||||
(define-minor-mode +org-pretty-mode
|
||||
"Hides emphasis markers and toggles pretty entities."
|
||||
:init-value nil
|
||||
:lighter " *"
|
||||
:group 'evil-org
|
||||
(setq org-hide-emphasis-markers +org-pretty-mode)
|
||||
(org-toggle-pretty-entities)
|
||||
(with-silent-modifications
|
||||
;; In case the above un-align tables
|
||||
(org-table-map-tables 'org-table-align t)))
|
||||
|
||||
|
||||
;;
|
||||
;;; Commands
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/dwim-at-point (&optional arg)
|
||||
"Do-what-I-mean at point.
|
||||
|
||||
If on a:
|
||||
- checkbox list item or todo heading: toggle it.
|
||||
- clock: update its time.
|
||||
- headline: cycle ARCHIVE subtrees, toggle latex fragments and inline images in
|
||||
subtree; update statistics cookies/checkboxes and ToCs.
|
||||
- footnote reference: jump to the footnote's definition
|
||||
- footnote definition: jump to the first reference of this footnote
|
||||
- table-row or a TBLFM: recalculate the table's formulas
|
||||
- table-cell: clear it and go into insert mode. If this is a formula cell,
|
||||
recaluclate it instead.
|
||||
- babel-call: execute the source block
|
||||
- statistics-cookie: update it.
|
||||
- latex fragment: toggle it.
|
||||
- link: follow it
|
||||
- otherwise, refresh all inline images in current tree."
|
||||
(interactive "P")
|
||||
(if (button-at (point))
|
||||
(call-interactively #'push-button)
|
||||
(let* ((context (org-element-context))
|
||||
(type (org-element-type context)))
|
||||
;; skip over unimportant contexts
|
||||
(while (and context (memq type '(verbatim code bold italic underline strike-through subscript superscript)))
|
||||
(setq context (org-element-property :parent context)
|
||||
type (org-element-type context)))
|
||||
(pcase type
|
||||
((or `citation `citation-reference)
|
||||
(org-cite-follow context arg))
|
||||
|
||||
(`headline
|
||||
(cond ((memq (bound-and-true-p org-goto-map)
|
||||
(current-active-maps))
|
||||
(org-goto-ret))
|
||||
((and (fboundp 'toc-org-insert-toc)
|
||||
(member "TOC" (org-get-tags)))
|
||||
(toc-org-insert-toc)
|
||||
(message "Updating table of contents"))
|
||||
((string= "ARCHIVE" (car-safe (org-get-tags)))
|
||||
(org-force-cycle-archived))
|
||||
((or (org-element-property :todo-type context)
|
||||
(org-element-property :scheduled context))
|
||||
(org-todo
|
||||
(if (eq (org-element-property :todo-type context) 'done)
|
||||
(or (car (+org-get-todo-keywords-for (org-element-property :todo-keyword context)))
|
||||
'todo)
|
||||
'done))))
|
||||
;; Update any metadata or inline previews in this subtree
|
||||
(org-update-checkbox-count)
|
||||
(org-update-parent-todo-statistics)
|
||||
(when (and (fboundp 'toc-org-insert-toc)
|
||||
(member "TOC" (org-get-tags)))
|
||||
(toc-org-insert-toc)
|
||||
(message "Updating table of contents"))
|
||||
(let* ((beg (if (org-before-first-heading-p)
|
||||
(line-beginning-position)
|
||||
(save-excursion (org-back-to-heading) (point))))
|
||||
(end (if (org-before-first-heading-p)
|
||||
(line-end-position)
|
||||
(save-excursion (org-end-of-subtree) (point))))
|
||||
(overlays (ignore-errors (overlays-in beg end)))
|
||||
(latex-overlays
|
||||
(cl-find-if (lambda (o) (eq (overlay-get o 'org-overlay-type) 'org-latex-overlay))
|
||||
overlays))
|
||||
(image-overlays
|
||||
(cl-find-if (lambda (o) (overlay-get o 'org-image-overlay))
|
||||
overlays)))
|
||||
(+org--toggle-inline-images-in-subtree beg end)
|
||||
(if (or image-overlays latex-overlays)
|
||||
(org-clear-latex-preview beg end)
|
||||
(org--latex-preview-region beg end))))
|
||||
|
||||
(`clock (org-clock-update-time-maybe))
|
||||
|
||||
(`footnote-reference
|
||||
(org-footnote-goto-definition (org-element-property :label context)))
|
||||
|
||||
(`footnote-definition
|
||||
(org-footnote-goto-previous-reference (org-element-property :label context)))
|
||||
|
||||
((or `planning `timestamp)
|
||||
(org-follow-timestamp-link))
|
||||
|
||||
((or `table `table-row)
|
||||
(if (org-at-TBLFM-p)
|
||||
(org-table-calc-current-TBLFM)
|
||||
(ignore-errors
|
||||
(save-excursion
|
||||
(goto-char (org-element-property :contents-begin context))
|
||||
(org-call-with-arg 'org-table-recalculate (or arg t))))))
|
||||
|
||||
(`table-cell
|
||||
(org-table-blank-field)
|
||||
(org-table-recalculate arg)
|
||||
(when (and (string-empty-p (string-trim (org-table-get-field)))
|
||||
(bound-and-true-p evil-local-mode))
|
||||
(evil-change-state 'insert)))
|
||||
|
||||
(`babel-call
|
||||
(org-babel-lob-execute-maybe))
|
||||
|
||||
(`statistics-cookie
|
||||
(save-excursion (org-update-statistics-cookies arg)))
|
||||
|
||||
((or `src-block `inline-src-block)
|
||||
(org-babel-execute-src-block arg))
|
||||
|
||||
((or `latex-fragment `latex-environment)
|
||||
(org-latex-preview arg))
|
||||
|
||||
(`link
|
||||
(let* ((lineage (org-element-lineage context '(link) t))
|
||||
(path (org-element-property :path lineage)))
|
||||
(if (or (equal (org-element-property :type lineage) "img")
|
||||
(and path (image-type-from-file-name path)))
|
||||
(+org--toggle-inline-images-in-subtree
|
||||
(org-element-property :begin lineage)
|
||||
(org-element-property :end lineage))
|
||||
(org-open-at-point arg))))
|
||||
|
||||
((guard (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)))))
|
||||
|
||||
(_
|
||||
(if (or (org-in-regexp org-ts-regexp-both nil t)
|
||||
(org-in-regexp org-tsr-regexp-both nil t)
|
||||
(org-in-regexp org-link-any-re nil t))
|
||||
(call-interactively #'org-open-at-point)
|
||||
(+org--toggle-inline-images-in-subtree
|
||||
(org-element-property :begin context)
|
||||
(org-element-property :end context))))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/shift-return (&optional arg)
|
||||
"Insert a literal newline, or dwim in tables.
|
||||
Executes `org-table-copy-down' if in table."
|
||||
(interactive "p")
|
||||
(if (org-at-table-p)
|
||||
(org-table-copy-down arg)
|
||||
(org-return nil arg)))
|
||||
|
||||
|
||||
;; I use these instead of `org-insert-item' or `org-insert-heading' because they
|
||||
;; impose bizarre whitespace rules depending on cursor location and many
|
||||
;; settings. These commands have a much simpler responsibility.
|
||||
;;;###autoload
|
||||
(defun +org/insert-item-below (count)
|
||||
"Inserts a new heading, table cell or item below the current one."
|
||||
(interactive "p")
|
||||
(dotimes (_ count) (+org--insert-item 'below)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/insert-item-above (count)
|
||||
"Inserts a new heading, table cell or item above the current one."
|
||||
(interactive "p")
|
||||
(dotimes (_ count) (+org--insert-item 'above)))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/toggle-last-clock (arg)
|
||||
"Toggles last clocked item.
|
||||
|
||||
Clock out if an active clock is running (or cancel it if prefix ARG is non-nil).
|
||||
|
||||
If no clock is active, then clock into the last item. See `org-clock-in-last' to
|
||||
see how ARG affects this command."
|
||||
(interactive "P")
|
||||
(require 'org-clock)
|
||||
(cond ((org-clocking-p)
|
||||
(if arg
|
||||
(org-clock-cancel)
|
||||
(org-clock-out)))
|
||||
((and (null org-clock-history)
|
||||
(or (org-on-heading-p)
|
||||
(org-at-item-p))
|
||||
(y-or-n-p "No active clock. Clock in on current item?"))
|
||||
(org-clock-in))
|
||||
((org-clock-in-last arg))))
|
||||
|
||||
|
||||
;;; Folds
|
||||
;;;###autoload
|
||||
(defalias #'+org/toggle-fold #'+org-cycle-only-current-subtree-h)
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/open-fold ()
|
||||
"Open the current fold (not but its children)."
|
||||
(interactive)
|
||||
(+org/toggle-fold t))
|
||||
|
||||
;;;###autoload
|
||||
(defalias #'+org/close-fold #'outline-hide-subtree)
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/close-all-folds (&optional level)
|
||||
"Close all folds in the buffer (or below LEVEL)."
|
||||
(interactive "p")
|
||||
(outline-hide-sublevels (or level 1)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/open-all-folds (&optional level)
|
||||
"Open all folds in the buffer (or up to LEVEL)."
|
||||
(interactive "P")
|
||||
(if (integerp level)
|
||||
(outline-hide-sublevels level)
|
||||
(outline-show-all)))
|
||||
|
||||
(defun +org--get-foldlevel ()
|
||||
(let ((max 1))
|
||||
(save-restriction
|
||||
(narrow-to-region (window-start) (window-end))
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (not (eobp))
|
||||
(org-next-visible-heading 1)
|
||||
(when (outline-invisible-p (line-end-position))
|
||||
(let ((level (org-outline-level)))
|
||||
(when (> level max)
|
||||
(setq max level))))))
|
||||
max)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/show-next-fold-level (&optional count)
|
||||
"Decrease the fold-level of the visible area of the buffer. This unfolds
|
||||
another level of headings on each invocation."
|
||||
(interactive "p")
|
||||
(let ((new-level (+ (+org--get-foldlevel) (or count 1))))
|
||||
(outline-hide-sublevels new-level)
|
||||
(message "Folded to level %s" new-level)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/hide-next-fold-level (&optional count)
|
||||
"Increase the global fold-level of the visible area of the buffer. This folds
|
||||
another level of headings on each invocation."
|
||||
(interactive "p")
|
||||
(let ((new-level (max 1 (- (+org--get-foldlevel) (or count 1)))))
|
||||
(outline-hide-sublevels new-level)
|
||||
(message "Folded to level %s" new-level)))
|
||||
|
||||
|
||||
;;
|
||||
;;; Hooks
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-indent-maybe-h ()
|
||||
"Indent the current item (header or item), if possible.
|
||||
Made for `org-tab-first-hook' in evil-mode."
|
||||
(interactive)
|
||||
(cond ((not (and (bound-and-true-p evil-local-mode)
|
||||
(evil-insert-state-p)))
|
||||
nil)
|
||||
((and (bound-and-true-p org-cdlatex-mode)
|
||||
(or (org-inside-LaTeX-fragment-p)
|
||||
(org-inside-latex-macro-p)))
|
||||
nil)
|
||||
((org-at-item-p)
|
||||
(if (eq this-command 'org-shifttab)
|
||||
(org-outdent-item-tree)
|
||||
(org-indent-item-tree))
|
||||
t)
|
||||
((org-at-heading-p)
|
||||
(ignore-errors
|
||||
(if (eq this-command 'org-shifttab)
|
||||
(org-promote)
|
||||
(org-demote)))
|
||||
t)
|
||||
((org-in-src-block-p t)
|
||||
(org-babel-do-in-edit-buffer
|
||||
(call-interactively #'indent-for-tab-command))
|
||||
t)
|
||||
((and (save-excursion
|
||||
(skip-chars-backward " \t")
|
||||
(bolp))
|
||||
(org-in-subtree-not-table-p))
|
||||
(call-interactively #'tab-to-tab-stop)
|
||||
t)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-yas-expand-maybe-h ()
|
||||
"Expand a yasnippet snippet, if trigger exists at point or region is active.
|
||||
Made for `org-tab-first-hook'."
|
||||
(when (and (featurep! :editor snippets)
|
||||
(require 'yasnippet nil t)
|
||||
(bound-and-true-p yas-minor-mode))
|
||||
(and (let ((major-mode (cond ((org-in-src-block-p t)
|
||||
(org-src-get-lang-mode (org-eldoc-get-src-lang)))
|
||||
((org-inside-LaTeX-fragment-p)
|
||||
'latex-mode)
|
||||
(major-mode)))
|
||||
(org-src-tab-acts-natively nil) ; causes breakages
|
||||
;; Smart indentation doesn't work with yasnippet, and painfully slow
|
||||
;; in the few cases where it does.
|
||||
(yas-indent-line 'fixed))
|
||||
(cond ((and (or (not (bound-and-true-p evil-local-mode))
|
||||
(evil-insert-state-p)
|
||||
(evil-emacs-state-p))
|
||||
(or (and (bound-and-true-p yas--tables)
|
||||
(gethash major-mode yas--tables))
|
||||
(progn (yas-reload-all) t))
|
||||
(yas--templates-for-key-at-point))
|
||||
(yas-expand)
|
||||
t)
|
||||
((use-region-p)
|
||||
(yas-insert-snippet)
|
||||
t)))
|
||||
;; HACK Yasnippet breaks org-superstar-mode because yasnippets is
|
||||
;; overzealous about cleaning up overlays.
|
||||
(when (bound-and-true-p org-superstar-mode)
|
||||
(org-superstar-restart)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-cycle-only-current-subtree-h (&optional arg)
|
||||
"Toggle the local fold at the point, and no deeper.
|
||||
`org-cycle's standard behavior is to cycle between three levels: collapsed,
|
||||
subtree and whole document. This is slow, especially in larger org buffer. Most
|
||||
of the time I just want to peek into the current subtree -- at most, expand
|
||||
*only* the current subtree.
|
||||
|
||||
All my (performant) foldings needs are met between this and `org-show-subtree'
|
||||
(on zO for evil users), and `org-cycle' on shift-TAB if I need it."
|
||||
(interactive "P")
|
||||
(unless (or (eq this-command 'org-shifttab)
|
||||
(and (bound-and-true-p org-cdlatex-mode)
|
||||
(or (org-inside-LaTeX-fragment-p)
|
||||
(org-inside-latex-macro-p))))
|
||||
(save-excursion
|
||||
(org-beginning-of-line)
|
||||
(let (invisible-p)
|
||||
(when (and (org-at-heading-p)
|
||||
(or org-cycle-open-archived-trees
|
||||
(not (member org-archive-tag (org-get-tags))))
|
||||
(or (not arg)
|
||||
(setq invisible-p (outline-invisible-p (line-end-position)))))
|
||||
(unless invisible-p
|
||||
(setq org-cycle-subtree-status 'subtree))
|
||||
(org-cycle-internal-local)
|
||||
t)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-make-last-point-visible-h ()
|
||||
"Unfold subtree around point if saveplace places us in a folded region."
|
||||
(and (not org-inhibit-startup)
|
||||
(not org-inhibit-startup-visibility-stuff)
|
||||
;; Must be done on a timer because `org-show-set-visibility' (used by
|
||||
;; `org-reveal') relies on overlays that aren't immediately available
|
||||
;; when `org-mode' first initializes.
|
||||
(run-at-time 0.1 nil #'org-reveal '(4))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-remove-occur-highlights-h ()
|
||||
"Remove org occur highlights on ESC in normal mode."
|
||||
(when org-occur-highlights
|
||||
(org-remove-occur-highlights)
|
||||
t))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-enable-auto-update-cookies-h ()
|
||||
"Update statistics cookies when saving or exiting insert mode (`evil-mode')."
|
||||
(when (bound-and-true-p evil-local-mode)
|
||||
(add-hook 'evil-insert-state-exit-hook #'org-update-parent-todo-statistics nil t))
|
||||
(add-hook 'before-save-hook #'org-update-parent-todo-statistics nil t))
|
||||
1332
.config/emacs/modules/lang/org/config.el
Normal file
1332
.config/emacs/modules/lang/org/config.el
Normal file
File diff suppressed because it is too large
Load Diff
42
.config/emacs/modules/lang/org/contrib/brain.el
Normal file
42
.config/emacs/modules/lang/org/contrib/brain.el
Normal file
@@ -0,0 +1,42 @@
|
||||
;;; lang/org/contrib/brain.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +brain)
|
||||
|
||||
(use-package! org-brain
|
||||
:defer t
|
||||
:init
|
||||
(setq org-brain-visualize-default-choices 'all
|
||||
org-brain-title-max-length 24
|
||||
org-brain-include-file-entries nil
|
||||
org-brain-file-entries-use-title nil)
|
||||
|
||||
:config
|
||||
(set-popup-rule! "^\\*org-brain"
|
||||
:side 'right :size 1.00 :select t :quit nil :ttl nil)
|
||||
|
||||
(cl-pushnew '("b" "Brain" plain (function org-brain-goto-end)
|
||||
"* %i%?" :empty-lines 1)
|
||||
org-capture-templates
|
||||
:key #'car :test #'equal)
|
||||
|
||||
(when (featurep! :editor evil +everywhere)
|
||||
;; TODO Make a proper evil keybind scheme for org-brain
|
||||
;; REVIEW This should be handled upstream by evil-collection
|
||||
(set-evil-initial-state!
|
||||
'(org-brain-visualize-mode
|
||||
org-brain-select-map
|
||||
org-brain-move-map
|
||||
org-brain-polymode-map)
|
||||
'normal)
|
||||
(defun +org--evilify-map (map)
|
||||
(let (keys)
|
||||
(map-keymap (lambda (event function)
|
||||
(push function keys)
|
||||
(push (vector event) keys))
|
||||
map)
|
||||
(apply #'evil-define-key* 'normal map keys)))
|
||||
|
||||
(+org--evilify-map org-brain-visualize-mode-map)
|
||||
(+org--evilify-map org-brain-select-map)
|
||||
(+org--evilify-map org-brain-move-map)
|
||||
(after! polymode
|
||||
(+org--evilify-map org-brain-polymode-map))))
|
||||
68
.config/emacs/modules/lang/org/contrib/dragndrop.el
Normal file
68
.config/emacs/modules/lang/org/contrib/dragndrop.el
Normal file
@@ -0,0 +1,68 @@
|
||||
;;; lang/org/contrib/dragndrop.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +dragndrop)
|
||||
|
||||
(use-package! org-download
|
||||
:commands
|
||||
org-download-dnd
|
||||
org-download-yank
|
||||
org-download-screenshot
|
||||
org-download-clipboard
|
||||
org-download-dnd-base64
|
||||
:init
|
||||
;; HACK We add these manually so that org-download is truly lazy-loaded
|
||||
(pushnew! dnd-protocol-alist
|
||||
'("^\\(?:https?\\|ftp\\|file\\|nfs\\):" . org-download-dnd)
|
||||
'("^data:" . org-download-dnd-base64))
|
||||
(advice-add #'org-download-enable :override #'ignore)
|
||||
|
||||
(after! org
|
||||
;; A shorter link to attachments
|
||||
(+org-define-basic-link "download" (lambda () (or org-download-image-dir org-attach-id-dir "."))
|
||||
:image-data-fun #'+org-image-file-data-fn
|
||||
:requires 'org-download))
|
||||
:config
|
||||
(unless org-download-image-dir
|
||||
(setq org-download-image-dir org-attach-id-dir))
|
||||
(setq org-download-method 'attach
|
||||
org-download-timestamp "_%Y%m%d_%H%M%S"
|
||||
org-download-screenshot-method
|
||||
(cond (IS-MAC "screencapture -i %s")
|
||||
(IS-LINUX
|
||||
(cond ((executable-find "maim") "maim -s %s")
|
||||
((executable-find "scrot") "scrot -s %s")
|
||||
((executable-find "gnome-screenshot") "gnome-screenshot -a -f %s"))))
|
||||
|
||||
org-download-heading-lvl nil
|
||||
org-download-link-format "[[download:%s]]\n"
|
||||
org-download-annotate-function (lambda (_link) "")
|
||||
org-download-link-format-function
|
||||
(lambda (filename)
|
||||
(if (eq org-download-method 'attach)
|
||||
(format "[[attachment:%s]]\n"
|
||||
(org-link-escape
|
||||
(file-relative-name filename (org-attach-dir))))
|
||||
;; Handle non-image files a little differently. Images should be
|
||||
;; inserted as normal with previews. Other files, like pdfs or zips,
|
||||
;; should be linked to, with an icon indicating the type of file.
|
||||
(format (concat (unless (image-type-from-file-name filename)
|
||||
(concat (+org-attach-icon-for filename)
|
||||
" "))
|
||||
org-download-link-format)
|
||||
(org-link-escape
|
||||
(funcall org-download-abbreviate-filename-function filename)))))
|
||||
org-download-abbreviate-filename-function
|
||||
(lambda (path)
|
||||
(if (file-in-directory-p path org-download-image-dir)
|
||||
(file-relative-name path org-download-image-dir)
|
||||
path)))
|
||||
|
||||
(defadvice! +org--dragndrop-then-display-inline-images-a (_link filename)
|
||||
:after #'org-download-insert-link
|
||||
(when (image-type-from-file-name filename)
|
||||
(save-excursion
|
||||
(org-display-inline-images
|
||||
t t
|
||||
(progn (org-back-to-heading t) (point))
|
||||
(progn (org-end-of-subtree t t)
|
||||
(when (and (org-at-heading-p) (not (eobp))) (backward-char 1))
|
||||
(point)))))))
|
||||
41
.config/emacs/modules/lang/org/contrib/ipython.el
Normal file
41
.config/emacs/modules/lang/org/contrib/ipython.el
Normal file
@@ -0,0 +1,41 @@
|
||||
;;; lang/org/contrib/babel.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +ipython)
|
||||
|
||||
(use-package! ob-ipython
|
||||
:defer t
|
||||
:init
|
||||
(defvar +ob-ipython-local-runtime-dir nil)
|
||||
|
||||
(setq ob-ipython-resources-dir ".ob-ipython-resrc")
|
||||
|
||||
(add-hook! '+org-babel-load-functions
|
||||
(defun +org-babel-load-ipython-h (lang)
|
||||
(and (string-prefix-p "jupyter-" (symbol-name lang))
|
||||
(require 'ob-ipython nil t))))
|
||||
|
||||
(after! org-src
|
||||
(add-to-list 'org-src-lang-modes '("ipython" . python)))
|
||||
(after! ox-latex
|
||||
(add-to-list 'org-latex-minted-langs '(ipython "python")))
|
||||
:config
|
||||
(set-popup-rules!
|
||||
'(("\\*ob-ipython.*"
|
||||
:slot 2 :side right :size 100 :height 0.2
|
||||
:select nil :quit nil :ttl nil)
|
||||
("^ \\*Python"
|
||||
:slot 0 :side right :size 100
|
||||
:select nil :quit nil :ttl nil)))
|
||||
|
||||
;; advices for remote kernel and org-src-edit
|
||||
(advice-add #'ob-ipython--create-repl :override #'+org-ob-ipython-create-repl-a)
|
||||
(advice-add #'org-babel-edit-prep:ipython :override #'+org-babel-edit-prep:ipython-a)
|
||||
(advice-add #'org-babel-execute:ipython :before #'+org-babel-execute:ipython-a)
|
||||
(advice-add #'org-babel-ipython-initiate-session :override #'+org-ob-ipython-initiate-session-a)
|
||||
|
||||
;; retina resolution image hack
|
||||
(when IS-MAC
|
||||
(advice-add #'ob-ipython--write-base64-string :around #'+org-ob-ipython-write-base64-string-a))
|
||||
|
||||
;; ipython has its own async keyword, disable ipython in ob-async.
|
||||
(after! ob-async
|
||||
(add-to-list 'ob-async-no-async-languages-alist "ipython")))
|
||||
71
.config/emacs/modules/lang/org/contrib/journal.el
Normal file
71
.config/emacs/modules/lang/org/contrib/journal.el
Normal file
@@ -0,0 +1,71 @@
|
||||
;;; lang/org/contrib/journal.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +journal)
|
||||
|
||||
(use-package! org-journal
|
||||
:defer t
|
||||
:init
|
||||
;; HACK `org-journal' adds a `magic-mode-alist' entry for detecting journal
|
||||
;; files, but this causes us lazy loaders a big problem: an unacceptable
|
||||
;; delay on the first file the user opens, because calling the autoloaded
|
||||
;; `org-journal-is-journal' pulls all of `org' with it. So, we replace it
|
||||
;; with our own, extra layer of heuristics.
|
||||
(add-to-list 'magic-mode-alist '(+org-journal-p . org-journal-mode))
|
||||
|
||||
(defun +org-journal-p ()
|
||||
"Wrapper around `org-journal-is-journal' to lazy load `org-journal'."
|
||||
(when-let (buffer-file-name (buffer-file-name (buffer-base-buffer)))
|
||||
(if (or (featurep 'org-journal)
|
||||
(and (file-in-directory-p
|
||||
buffer-file-name (expand-file-name org-journal-dir org-directory))
|
||||
(require 'org-journal nil t)))
|
||||
(org-journal-is-journal))))
|
||||
|
||||
;; `org-journal-dir' defaults to "~/Documents/journal/", which is an odd
|
||||
;; default, so we change it to {org-directory}/journal (we expand it after
|
||||
;; org-journal is loaded).
|
||||
(setq org-journal-dir "journal/"
|
||||
org-journal-cache-file (concat doom-cache-dir "org-journal"))
|
||||
|
||||
:config
|
||||
;; Remove the orginal journal file detector and rely on `+org-journal-p'
|
||||
;; instead, to avoid loading org-journal until the last possible moment.
|
||||
(setq magic-mode-alist (assq-delete-all 'org-journal-is-journal magic-mode-alist))
|
||||
|
||||
;; `org-journal' can't deal with symlinks, so resolve them here.
|
||||
(setq org-journal-dir (expand-file-name org-journal-dir org-directory)
|
||||
;; Doom opts for an "open in a popup or here" strategy as a default.
|
||||
;; Open in "other window" is less predictable, and can replace a window
|
||||
;; we wanted to keep visible.
|
||||
org-journal-find-file #'find-file)
|
||||
|
||||
;; Setup carryover to include all configured TODO states. We cannot carry over
|
||||
;; [ ] keywords because `org-journal-carryover-items's syntax cannot correctly
|
||||
;; interpret it as anything other than a date.
|
||||
(setq org-journal-carryover-items "TODO=\"TODO\"|TODO=\"PROJ\"|TODO=\"STRT\"|TODO=\"WAIT\"|TODO=\"HOLD\"")
|
||||
|
||||
(set-company-backend! 'org-journal-mode 'company-capf 'company-dabbrev)
|
||||
|
||||
(map! (:map org-journal-mode-map
|
||||
:n "]f" #'org-journal-next-entry
|
||||
:n "[f" #'org-journal-previous-entry
|
||||
:n "C-n" #'org-journal-next-entry
|
||||
:n "C-p" #'org-journal-previous-entry)
|
||||
(:map org-journal-search-mode-map
|
||||
"C-n" #'org-journal-search-next
|
||||
"C-p" #'org-journal-search-previous)
|
||||
:localleader
|
||||
(:map org-journal-mode-map
|
||||
"c" #'org-journal-new-entry
|
||||
"d" #'org-journal-new-date-entry
|
||||
"n" #'org-journal-next-entry
|
||||
"p" #'org-journal-previous-entry
|
||||
(:prefix "s"
|
||||
"s" #'org-journal-search
|
||||
"f" #'org-journal-search-forever
|
||||
"F" #'org-journal-search-future
|
||||
"w" #'org-journal-search-calendar-week
|
||||
"m" #'org-journal-search-calendar-month
|
||||
"y" #'org-journal-search-calendar-year))
|
||||
(:map org-journal-search-mode-map
|
||||
"n" #'org-journal-search-next
|
||||
"p" #'org-journal-search-prev)))
|
||||
40
.config/emacs/modules/lang/org/contrib/jupyter.el
Normal file
40
.config/emacs/modules/lang/org/contrib/jupyter.el
Normal file
@@ -0,0 +1,40 @@
|
||||
;;; lang/org/contrib/jupyter.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +jupyter)
|
||||
|
||||
(use-package! ob-jupyter
|
||||
:defer t
|
||||
:init
|
||||
(after! ob-async
|
||||
(pushnew! ob-async-no-async-languages-alist
|
||||
"jupyter-python"
|
||||
"jupyter-julia"
|
||||
"jupyter-R"))
|
||||
|
||||
(after! org-src
|
||||
(dolist (lang '(python julia R))
|
||||
(cl-pushnew (cons (format "jupyter-%s" lang) lang)
|
||||
org-src-lang-modes :key #'car)))
|
||||
|
||||
(add-hook! '+org-babel-load-functions
|
||||
(defun +org-babel-load-jupyter-h (lang)
|
||||
(when (string-prefix-p "jupyter-" (symbol-name lang))
|
||||
(require 'jupyter)
|
||||
(let* ((lang-name (symbol-name lang))
|
||||
(lang-tail (string-remove-prefix "jupyter-" lang-name)))
|
||||
(and (not (assoc lang-tail org-src-lang-modes))
|
||||
(require (intern (format "ob-%s" lang-tail))
|
||||
nil t)
|
||||
(add-to-list 'org-src-lang-modes (cons lang-name (intern lang-tail)))))
|
||||
(with-demoted-errors "Jupyter: %s"
|
||||
(require lang nil t)
|
||||
(require 'ob-jupyter nil t)))))
|
||||
:config
|
||||
(defadvice! +org--ob-jupyter-initiate-session-a (&rest _)
|
||||
:after #'org-babel-jupyter-initiate-session
|
||||
(unless (bound-and-true-p jupyter-org-interaction-mode)
|
||||
(jupyter-org-interaction-mode)))
|
||||
|
||||
;; Remove text/html since it's not human readable
|
||||
(delq! :text/html jupyter-org-mime-types)
|
||||
|
||||
(require 'tramp))
|
||||
14
.config/emacs/modules/lang/org/contrib/noter.el
Normal file
14
.config/emacs/modules/lang/org/contrib/noter.el
Normal file
@@ -0,0 +1,14 @@
|
||||
;;; lang/org/contrib/noter.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +noter)
|
||||
|
||||
(use-package! org-noter
|
||||
:defer t
|
||||
:preface
|
||||
;; Allow the user to preempt this and set the document search path
|
||||
;; If not set then use `org-directory'
|
||||
(defvar org-noter-notes-search-path nil)
|
||||
:config
|
||||
(unless org-noter-notes-search-path
|
||||
(setq org-noter-notes-search-path (list org-directory)))
|
||||
(setq org-noter-auto-save-last-location t
|
||||
org-noter-separate-notes-from-heading t))
|
||||
17
.config/emacs/modules/lang/org/contrib/pomodoro.el
Normal file
17
.config/emacs/modules/lang/org/contrib/pomodoro.el
Normal file
@@ -0,0 +1,17 @@
|
||||
;;; lang/org/contrib/pomodoro.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +pomodoro)
|
||||
|
||||
(after! org-pomodoro
|
||||
;; prefer PulseAudio to ALSA in $current_year
|
||||
(setq org-pomodoro-audio-player (or (executable-find "paplay")
|
||||
org-pomodoro-audio-player))
|
||||
|
||||
;; configure pomodoro alerts to use growl or libnotify
|
||||
(alert-add-rule :category "org-pomodoro"
|
||||
:style (cond (alert-growl-command
|
||||
'growl)
|
||||
(alert-notifier-command
|
||||
'notifier)
|
||||
(alert-libnotify-command
|
||||
'libnotify)
|
||||
(alert-default-style))))
|
||||
67
.config/emacs/modules/lang/org/contrib/present.el
Normal file
67
.config/emacs/modules/lang/org/contrib/present.el
Normal file
@@ -0,0 +1,67 @@
|
||||
;;; lang/org/contrib/present.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +present)
|
||||
|
||||
(defvar +org-present-text-scale 5
|
||||
"The `text-scale-amount' for `org-tree-slide-mode'.")
|
||||
|
||||
(defvar +org-present-hide-first-heading nil
|
||||
"If non-nil, hide the top-level heading for the current slide.
|
||||
|
||||
Some presenters think the first level heading takes up too much space, or use
|
||||
them as slide names, rather than titles. Instead, you can use second level
|
||||
headings as titles, and you have more freedom to place them wherever you like.")
|
||||
|
||||
|
||||
(after! ox
|
||||
(add-to-list 'org-export-backends 'beamer))
|
||||
|
||||
|
||||
;;
|
||||
;;; Packages
|
||||
|
||||
(use-package! org-re-reveal
|
||||
:after ox
|
||||
:config
|
||||
(setq org-re-reveal-root (expand-file-name "../../" (locate-library "dist/reveal.js" t))
|
||||
org-re-reveal-revealjs-version "4"))
|
||||
|
||||
|
||||
(use-package! org-tree-slide
|
||||
:commands org-tree-slide-mode
|
||||
:config
|
||||
(org-tree-slide-simple-profile)
|
||||
(setq org-tree-slide-activate-message " "
|
||||
org-tree-slide-deactivate-message " "
|
||||
org-tree-slide-modeline-display nil
|
||||
org-tree-slide-heading-emphasis t)
|
||||
|
||||
(add-hook 'org-tree-slide-after-narrow-hook #'org-display-inline-images)
|
||||
(add-hook 'org-tree-slide-mode-hook #'+org-present-prettify-slide-h)
|
||||
(add-hook 'org-tree-slide-play-hook #'+org-present-hide-blocks-h)
|
||||
|
||||
(when (featurep! :editor evil)
|
||||
(map! :map org-tree-slide-mode-map
|
||||
:n [C-right] #'org-tree-slide-move-next-tree
|
||||
:n [C-left] #'org-tree-slide-move-previous-tree)
|
||||
(add-hook 'org-tree-slide-mode-hook #'evil-normalize-keymaps))
|
||||
|
||||
(defadvice! +org-present--hide-first-heading-maybe-a (fn &rest args)
|
||||
"Omit the first heading if `+org-present-hide-first-heading' is non-nil."
|
||||
:around #'org-tree-slide--display-tree-with-narrow
|
||||
(letf! (defun org-narrow-to-subtree ()
|
||||
(save-excursion
|
||||
(save-match-data
|
||||
(org-with-limited-levels
|
||||
(narrow-to-region
|
||||
(progn
|
||||
(when (org-before-first-heading-p)
|
||||
(org-next-visible-heading 1))
|
||||
(ignore-errors (org-up-heading-all 99))
|
||||
(when +org-present-hide-first-heading
|
||||
(forward-line 1))
|
||||
(point))
|
||||
(progn (org-end-of-subtree t t)
|
||||
(when (and (org-at-heading-p) (not (eobp)))
|
||||
(backward-char 1))
|
||||
(point)))))))
|
||||
(apply fn args))))
|
||||
24
.config/emacs/modules/lang/org/contrib/pretty.el
Normal file
24
.config/emacs/modules/lang/org/contrib/pretty.el
Normal file
@@ -0,0 +1,24 @@
|
||||
;;; lang/org/contrib/pretty.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +pretty)
|
||||
(after! org
|
||||
(setq org-highlight-latex-and-related '(native script entities)))
|
||||
|
||||
|
||||
(use-package! org-superstar ; "prettier" bullets
|
||||
:hook (org-mode . org-superstar-mode)
|
||||
:config
|
||||
;; Make leading stars truly invisible, by rendering them as spaces!
|
||||
(setq org-superstar-leading-bullet ?\s
|
||||
org-superstar-leading-fallback ?\s
|
||||
org-hide-leading-stars nil
|
||||
org-superstar-todo-bullet-alist
|
||||
'(("TODO" . 9744)
|
||||
("[ ]" . 9744)
|
||||
("DONE" . 9745)
|
||||
("[X]" . 9745))))
|
||||
|
||||
|
||||
(use-package! org-fancy-priorities ; priority icons
|
||||
:hook (org-mode . org-fancy-priorities-mode)
|
||||
:hook (org-agenda-mode . org-fancy-priorities-mode)
|
||||
:config (setq org-fancy-priorities-list '("⚑" "⬆" "■")))
|
||||
96
.config/emacs/modules/lang/org/contrib/roam.el
Normal file
96
.config/emacs/modules/lang/org/contrib/roam.el
Normal file
@@ -0,0 +1,96 @@
|
||||
;;; lang/org/contrib/roam.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +roam)
|
||||
|
||||
(defvar +org-roam-open-buffer-on-find-file t
|
||||
"If non-nil, open the org-roam buffer when opening an org roam file.")
|
||||
|
||||
|
||||
;;
|
||||
;;; Packages
|
||||
|
||||
(use-package! org-roam
|
||||
:hook (org-load . +org-init-roam-maybe-h)
|
||||
:hook (org-roam-backlinks-mode . turn-on-visual-line-mode)
|
||||
:commands (org-roam-buffer-toggle-display
|
||||
org-roam-dailies-find-date
|
||||
org-roam-dailies-find-today
|
||||
org-roam-dailies-find-tomorrow
|
||||
org-roam-dailies-find-yesterday)
|
||||
:preface
|
||||
;; Set this to nil so we can later detect if the user has set custom values
|
||||
;; for these variables. If not, default values will be set in the :config
|
||||
;; section.
|
||||
(defvar org-roam-directory nil)
|
||||
(defvar org-roam-db-location nil)
|
||||
:init
|
||||
(map! :after org
|
||||
:map org-mode-map
|
||||
:localleader
|
||||
:prefix ("m" . "org-roam")
|
||||
"b" #'org-roam-switch-to-buffer
|
||||
"f" #'org-roam-find-file
|
||||
"g" #'org-roam-graph
|
||||
"i" #'org-roam-insert
|
||||
"I" #'org-roam-insert-immediate
|
||||
"m" #'org-roam
|
||||
"t" #'org-roam-tag-add
|
||||
"T" #'org-roam-tag-delete
|
||||
(:prefix ("d" . "by date")
|
||||
:desc "Find previous note" "b" #'org-roam-dailies-find-previous-note
|
||||
:desc "Find date" "d" #'org-roam-dailies-find-date
|
||||
:desc "Find next note" "f" #'org-roam-dailies-find-next-note
|
||||
:desc "Find tomorrow" "m" #'org-roam-dailies-find-tomorrow
|
||||
:desc "Capture today" "n" #'org-roam-dailies-capture-today
|
||||
:desc "Find today" "t" #'org-roam-dailies-find-today
|
||||
:desc "Capture Date" "v" #'org-roam-dailies-capture-date
|
||||
:desc "Find yesterday" "y" #'org-roam-dailies-find-yesterday
|
||||
:desc "Find directory" "." #'org-roam-dailies-find-directory))
|
||||
:config
|
||||
(defun +org-init-roam-maybe-h ()
|
||||
"Activate `org-roam-mode'. If it fails, fail gracefully."
|
||||
(unless (with-demoted-errors "ORG ROAM ERROR: %s"
|
||||
(org-roam-mode +1)
|
||||
t)
|
||||
(message "To try reinitializing org-roam, run 'M-x org-roam-mode'")
|
||||
(org-roam-mode -1)))
|
||||
|
||||
(setq org-roam-directory
|
||||
(file-name-as-directory
|
||||
(file-truename
|
||||
(expand-file-name (or org-roam-directory "roam")
|
||||
org-directory)))
|
||||
org-roam-db-location (or org-roam-db-location
|
||||
(concat doom-etc-dir "org-roam.db"))
|
||||
;; Make org-roam buffer sticky; i.e. don't replace it when opening a
|
||||
;; file with an *-other-window command.
|
||||
org-roam-buffer-window-parameters '((no-delete-other-windows . t))
|
||||
org-roam-link-use-custom-faces 'everywhere
|
||||
org-roam-completion-everywhere t
|
||||
org-roam-completion-system
|
||||
(cond ((featurep! :completion helm) 'helm)
|
||||
((featurep! :completion ivy) 'ivy)
|
||||
((featurep! :completion ido) 'ido)
|
||||
('default)))
|
||||
|
||||
;; Normally, the org-roam buffer doesn't open until you explicitly call
|
||||
;; `org-roam'. If `+org-roam-open-buffer-on-find-file' is non-nil, the
|
||||
;; org-roam buffer will be opened for you when you use `org-roam-find-file'
|
||||
;; (but not `find-file', to limit the scope of this behavior).
|
||||
(add-hook! 'find-file-hook
|
||||
(defun +org-roam-open-buffer-maybe-h ()
|
||||
(and +org-roam-open-buffer-on-find-file
|
||||
(memq 'org-roam-buffer--update-maybe post-command-hook)
|
||||
(not (window-parameter nil 'window-side)) ; don't proc for popups
|
||||
(not (eq 'visible (org-roam-buffer--visibility)))
|
||||
(with-current-buffer (window-buffer)
|
||||
(org-roam-buffer--get-create)))))
|
||||
|
||||
;; Hide the mode line in the org-roam buffer, since it serves no purpose. This
|
||||
;; makes it easier to distinguish from other org buffers.
|
||||
(add-hook 'org-roam-buffer-prepare-hook #'hide-mode-line-mode))
|
||||
|
||||
|
||||
;; Since the org module lazy loads org-protocol (waits until an org URL is
|
||||
;; detected), we can safely chain `org-roam-protocol' to it.
|
||||
(use-package! org-roam-protocol
|
||||
:after org-protocol)
|
||||
185
.config/emacs/modules/lang/org/contrib/roam2.el
Normal file
185
.config/emacs/modules/lang/org/contrib/roam2.el
Normal file
@@ -0,0 +1,185 @@
|
||||
;;; lang/org/contrib/roam2.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +roam2)
|
||||
|
||||
(defvar +org-roam-open-buffer-on-find-file t
|
||||
"If non-nil, open the org-roam buffer when opening an org roam file.")
|
||||
|
||||
(defvar +org-roam-link-to-org-use-id 'create-if-interactive
|
||||
"`org-roam-directory' local value for `org-id-link-to-org-use-id'.
|
||||
It's not recommended to set this to nil in order for other parts
|
||||
of org-mode to properly utilize ID links.")
|
||||
|
||||
|
||||
;;
|
||||
;;; Packages
|
||||
|
||||
(use-package! org-roam
|
||||
:hook (org-load . +org-init-roam-h)
|
||||
:preface
|
||||
;; Set this to nil so we can later detect if the user has set custom values
|
||||
;; for these variables. If not, default values will be set in the :config
|
||||
;; section.
|
||||
(defvar org-roam-directory nil)
|
||||
(defvar org-roam-db-location nil)
|
||||
|
||||
:init
|
||||
(doom-load-packages-incrementally
|
||||
'(ansi-color dash f rx seq magit-section emacsql emacsql-sqlite))
|
||||
|
||||
;; Don't display warning message dedicated for v1 users. Need to be set early.
|
||||
(setq org-roam-v2-ack t)
|
||||
|
||||
(defadvice! +org-roam-suppress-sqlite-build-a (fn &rest args)
|
||||
"Suppress automatic building of sqlite3 binary when loading `org-roam'.
|
||||
This is a blocking operation that can take a while to complete
|
||||
and better be deferred when there will be an actual demand for
|
||||
the database. See `+org-init-roam-h' for the launch process."
|
||||
:around #'emacsql-sqlite-ensure-binary
|
||||
(if (not (boundp 'org-roam-db-version))
|
||||
(apply fn args)
|
||||
(advice-remove #'emacsql-sqlite-ensure-binary #'+org-roam-suppress-sqlite-build-a)
|
||||
nil))
|
||||
|
||||
:config
|
||||
(defun +org-init-roam-h ()
|
||||
"Setup `org-roam' but don't immediately initialize its database.
|
||||
Instead, initialize it when it will be actually needed."
|
||||
(letf! ((#'org-roam-db-sync #'ignore))
|
||||
(org-roam-setup))
|
||||
(defadvice! +org-roam-try-init-db-a (&rest _)
|
||||
"Try to initialize org-roam database at the last possible safe moment.
|
||||
In case of failure, fail gracefully."
|
||||
:before #'org-roam-db-query
|
||||
(message "Initializing org-roam database...")
|
||||
(let ((run-cleanup-p t))
|
||||
(unwind-protect
|
||||
;; Try to build the binary if it doesn't exist. In case of failure
|
||||
;; this will error, run the cleanup and exit, and in case of success
|
||||
;; this will return nil and sync the database.
|
||||
(setq run-cleanup-p (emacsql-sqlite-ensure-binary))
|
||||
(when run-cleanup-p
|
||||
(setq org-roam--sqlite-available-p nil)
|
||||
(org-roam-teardown)
|
||||
(message (concat "EmacSQL failied to build SQLite binary for org-roam; "
|
||||
"see *Compile-Log* buffer for details.\n"
|
||||
"To try reinitialize org-roam, run \"M-x org-roam-setup\"")))))
|
||||
(advice-remove 'org-roam-db-query #'+org-roam-try-init-db-a)
|
||||
(org-roam-db-sync)))
|
||||
|
||||
(setq org-roam-directory
|
||||
(thread-first (or org-roam-directory "roam")
|
||||
(expand-file-name org-directory)
|
||||
(file-truename)
|
||||
(file-name-as-directory))
|
||||
org-roam-db-location
|
||||
(or org-roam-db-location
|
||||
(concat doom-etc-dir "org-roam.db"))
|
||||
org-roam-node-display-template
|
||||
"${doom-hierarchy:*} ${doom-tags:45}"
|
||||
org-roam-completion-everywhere t
|
||||
org-roam-mode-section-functions
|
||||
#'(org-roam-backlinks-section
|
||||
org-roam-reflinks-section))
|
||||
|
||||
(setq-hook! 'org-roam-find-file-hook
|
||||
org-id-link-to-org-use-id +org-roam-link-to-org-use-id)
|
||||
|
||||
;; Normally, the org-roam buffer doesn't open until you explicitly call
|
||||
;; `org-roam'. If `+org-roam-open-buffer-on-find-file' is non-nil, the
|
||||
;; org-roam buffer will be opened for you whenever you visit a file in
|
||||
;; `org-roam-directory'.
|
||||
(add-hook! 'org-roam-find-file-hook :append
|
||||
(defun +org-roam-open-with-buffer-maybe-h ()
|
||||
(and +org-roam-open-buffer-on-find-file
|
||||
(not org-roam-capture--node) ;; don't proc for roam capture buffers
|
||||
(not org-capture-mode) ;; don't proc for normal capture buffers
|
||||
(not (eq 'visible (org-roam-buffer--visibility)))
|
||||
(org-roam-buffer-toggle))))
|
||||
|
||||
(set-popup-rules!
|
||||
`((,(regexp-quote org-roam-buffer) ; persistent org-roam buffer
|
||||
:side right :width .33 :height .5 :ttl nil :modeline nil :quit nil :slot 1)
|
||||
("^\\*org-roam: " ; node dedicated org-roam buffer
|
||||
:side right :width .33 :height .5 :ttl nil :modeline nil :quit nil :slot 2)))
|
||||
|
||||
(add-hook 'org-roam-mode-hook #'turn-on-visual-line-mode)
|
||||
|
||||
(map! (:map org-mode-map
|
||||
:localleader
|
||||
:prefix ("m" . "org-roam")
|
||||
"D" #'org-roam-demote-entire-buffer
|
||||
"f" #'org-roam-node-find
|
||||
"F" #'org-roam-ref-find
|
||||
"g" #'org-roam-graph
|
||||
"i" #'org-roam-node-insert
|
||||
"I" #'org-id-get-create
|
||||
"m" #'org-roam-buffer-toggle
|
||||
"M" #'org-roam-buffer-display-dedicated
|
||||
"n" #'org-roam-capture
|
||||
"r" #'org-roam-refile
|
||||
"R" #'org-roam-link-replace-all
|
||||
(:prefix ("d" . "by date")
|
||||
:desc "Goto previous note" "b" #'org-roam-dailies-goto-previous-note
|
||||
:desc "Goto date" "d" #'org-roam-dailies-goto-date
|
||||
:desc "Capture date" "D" #'org-roam-dailies-capture-date
|
||||
:desc "Goto next note" "f" #'org-roam-dailies-goto-next-note
|
||||
:desc "Goto tomorrow" "m" #'org-roam-dailies-goto-tomorrow
|
||||
:desc "Capture tomorrow" "M" #'org-roam-dailies-capture-tomorrow
|
||||
:desc "Capture today" "n" #'org-roam-dailies-capture-today
|
||||
:desc "Goto today" "t" #'org-roam-dailies-goto-today
|
||||
:desc "Capture today" "T" #'org-roam-dailies-capture-today
|
||||
:desc "Goto yesterday" "y" #'org-roam-dailies-goto-yesterday
|
||||
:desc "Capture yesterday" "Y" #'org-roam-dailies-capture-yesterday
|
||||
:desc "Find directory" "-" #'org-roam-dailies-find-directory)
|
||||
(:prefix ("o" . "node properties")
|
||||
"a" #'org-roam-alias-add
|
||||
"A" #'org-roam-alias-remove
|
||||
"t" #'org-roam-tag-add
|
||||
"T" #'org-roam-tag-remove
|
||||
"r" #'org-roam-ref-add
|
||||
"R" #'org-roam-ref-remove)))
|
||||
|
||||
(when (featurep! :editor evil +everywhere)
|
||||
(add-hook! 'org-roam-mode-hook
|
||||
(defun +org-roam-detach-magit-section-mode-map-h ()
|
||||
"Detach `magit-section-mode-map' from `org-roam-mode-map'.
|
||||
Inheriting its keymaps introduces a lot of conflicts in
|
||||
`org-roam-mode' based buffers, where Evil and leader keybindings
|
||||
will become completely overridden. This is because `magit-section'
|
||||
uses 'keymap text-property to attach section-unique keymaps, which
|
||||
has a higher level of precedence than `emulation-mode-map-alists'.
|
||||
|
||||
Note: We do this each time through the hook, because otherwise
|
||||
sections seems to ignore the detachment."
|
||||
(set-keymap-parent org-roam-mode-map nil)))
|
||||
|
||||
(map! :map org-roam-mode-map
|
||||
:nv "]" #'magit-section-forward-sibling
|
||||
:nv "[" #'magit-section-backward-sibling
|
||||
:nv "gj" #'magit-section-forward-sibling
|
||||
:nv "gk" #'magit-section-backward-sibling
|
||||
:nv "gr" #'revert-buffer
|
||||
:nv "gR" #'revert-buffer
|
||||
:nv "z1" #'magit-section-show-level-1
|
||||
:nv "z2" #'magit-section-show-level-2
|
||||
:nv "z3" #'magit-section-show-level-3
|
||||
:nv "z4" #'magit-section-show-level-4
|
||||
:nv "za" #'magit-section-toggle
|
||||
:nv "zc" #'magit-section-hide
|
||||
:nv "zC" #'magit-section-hide-children
|
||||
:nv "zo" #'magit-section-show
|
||||
:nv "zO" #'magit-section-show-children
|
||||
:nv "zr" #'magit-section-show-level-4-all
|
||||
:nv "C-j" #'magit-section-forward
|
||||
:nv "C-k" #'magit-section-backward
|
||||
:g "M-p" #'magit-section-backward-sibling
|
||||
:g "M-n" #'magit-section-forward-sibling
|
||||
:g [tab] #'magit-section-toggle
|
||||
:g [C-tab] #'magit-section-cycle
|
||||
:g [backtab] #'magit-section-cycle-global)))
|
||||
|
||||
|
||||
;; Since the org module lazy loads org-protocol (waits until an org URL is
|
||||
;; detected), we can safely chain `org-roam-protocol' to it.
|
||||
(use-package! org-roam-protocol
|
||||
:after org-protocol)
|
||||
30
.config/emacs/modules/lang/org/doctor.el
Normal file
30
.config/emacs/modules/lang/org/doctor.el
Normal file
@@ -0,0 +1,30 @@
|
||||
;; -*- lexical-binding: t; no-byte-compile: t; -*-
|
||||
;;; lang/org/doctor.el
|
||||
|
||||
(when (featurep! +gnuplot)
|
||||
(unless (executable-find "gnuplot")
|
||||
(warn! "Couldn't find gnuplot. org-plot/gnuplot will not work")))
|
||||
|
||||
(when (featurep! +roam)
|
||||
(unless (executable-find "sqlite3")
|
||||
(warn! "Couldn't find the sqlite3 executable. org-roam will not work.")))
|
||||
(when (or (featurep! +roam)
|
||||
(featurep! +roam2))
|
||||
(unless (executable-find "dot")
|
||||
(warn! "Couldn't find the dot executable (from graphviz). org-roam will not be able to generate graph visualizations.")))
|
||||
|
||||
(when (featurep! +dragndrop)
|
||||
(when IS-MAC
|
||||
(unless (executable-find "pngpaste")
|
||||
(warn! "Couldn't find the pngpaste executable. org-download-clipboard will not work.")))
|
||||
(when IS-LINUX
|
||||
(unless (or (executable-find "maim") (executable-find "scrot") (executable-find "gnome-screenshot"))
|
||||
(warn! "Couldn't find the maim, scrot or gnome-screenshot executable. org-download-clipboard will not work."))
|
||||
(if (string= "wayland" (getenv "XDG_SESSION_TYPE"))
|
||||
(unless (executable-find "wl-paste")
|
||||
(warn! "Couldn't find the wl-paste executable (from wl-clipboard). org-download-clipboard will not work."))
|
||||
(unless (executable-find "xclip")
|
||||
(warn! "Couldn't find the xclip executable. org-download-clipboard will not work."))))
|
||||
(when IS-WINDOWS
|
||||
(unless (executable-find "convert")
|
||||
(warn! "Couldn't find the convert program (from ImageMagick). org-download-clipboard will not work."))))
|
||||
127
.config/emacs/modules/lang/org/packages.el
Normal file
127
.config/emacs/modules/lang/org/packages.el
Normal file
@@ -0,0 +1,127 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/org/packages.el
|
||||
|
||||
(package! org
|
||||
:recipe (:host github
|
||||
;; REVIEW I intentionally avoid git.savannah.gnu.org because of SSL
|
||||
;; issues (see #5655), uptime issues, download time, and lack of
|
||||
;; shallow clone support.
|
||||
:repo "emacs-straight/org-mode"
|
||||
:files (:defaults "etc")
|
||||
:depth 1
|
||||
;; HACK Org requires a post-install compilation step to generate a
|
||||
;; org-version.el with org-release and org-git-version functions,
|
||||
;; using a 'git describe ...' call. This won't work in a sparse
|
||||
;; clone and I value smaller network burdens on users over
|
||||
;; non-essential variables so we fake it:
|
||||
:build t
|
||||
:pre-build
|
||||
(with-temp-file "org-version.el"
|
||||
(let ((version
|
||||
(with-temp-buffer
|
||||
(insert-file-contents (doom-path "lisp/org.el") nil 0 1024)
|
||||
(if (re-search-forward "^;; Version: \\([^\n-]+\\)" nil t)
|
||||
(match-string-no-properties 1)
|
||||
"Unknown"))))
|
||||
(insert (format "(defun org-release () %S)\n" version)
|
||||
(format "(defun org-git-version (&rest _) \"%s-??-%s\")\n"
|
||||
version (cdr (doom-call-process "git" "rev-parse" "--short" "HEAD")))
|
||||
"(provide 'org-version)\n"))))
|
||||
:pin "0c9b30e961ac7a20eb2e8985ab686c6940e79ef3")
|
||||
(package! org-contrib
|
||||
:recipe (:host github
|
||||
:repo "emacsmirror/org-contrib")
|
||||
:pin "e3183921779eb4f36a2170ebb58e43eb0e84a07e")
|
||||
|
||||
(package! avy)
|
||||
(package! htmlize :pin "dd27bc3f26efd728f2b1f01f9e4ac4f61f2ffbf9")
|
||||
(package! org-yt
|
||||
:recipe (:host github :repo "TobiasZawada/org-yt")
|
||||
:pin "40cc1ac76d741055cbefa13860d9f070a7ade001")
|
||||
(package! ox-clip :pin "05a14d56bbffe569d86f20b49ae31ed2ac7d1101")
|
||||
(package! toc-org :pin "df4ad6ff15e3b02f6322305638a441a636b9b37e")
|
||||
(package! org-cliplink :pin "13e0940b65d22bec34e2de4bc8cba1412a7abfbc")
|
||||
|
||||
(when (featurep! :editor evil +everywhere)
|
||||
(package! evil-org
|
||||
:recipe (:host github :repo "hlissner/evil-org-mode")
|
||||
:pin "a9706da260c45b98601bcd72b1d2c0a24a017700"))
|
||||
(when (featurep! :tools pdf)
|
||||
(package! org-pdftools :pin "a5b61bca3f8c91b0859bb0df1a929f9a31a57b99"))
|
||||
(when (featurep! :tools magit)
|
||||
(package! orgit :pin "f956d802f19ea495efa95af6c673588afeb3adc5")
|
||||
(when (featurep! :tools magit +forge)
|
||||
(package! orgit-forge :pin "365b75609a9454dccf5681eb6075ca53bd32af85")))
|
||||
(when (featurep! +brain)
|
||||
(package! org-brain :pin "46ca9f766322cff31279ecdf02251ff24a0e9431"))
|
||||
(when (featurep! +dragndrop)
|
||||
(package! org-download :pin "947ca223643d28e189480e607df68449c15786cb"))
|
||||
(when (featurep! +gnuplot)
|
||||
(package! gnuplot :pin "7138b139d2dca9683f1a81325c643b2744aa1ea3")
|
||||
(package! gnuplot-mode :pin "601f6392986f0cba332c87678d31ae0d0a496ce7"))
|
||||
(when (featurep! +ipython) ; DEPRECATED
|
||||
(package! ob-ipython :pin "7147455230841744fb5b95dcbe03320313a77124"))
|
||||
(when (featurep! +jupyter)
|
||||
(package! jupyter :pin "df343af5e9187a400a9291fa6a2b0c69f3ad0425"))
|
||||
(when (featurep! +journal)
|
||||
(package! org-journal :pin "71e8b10088ae52c4ac17f7af87020ea85fbc6ff7"))
|
||||
(when (featurep! +noter)
|
||||
(package! org-noter :pin "9ead81d42dd4dd5074782d239b2efddf9b8b7b3d"))
|
||||
(when (featurep! +pomodoro)
|
||||
(package! org-pomodoro :pin "aa07c11318f91219336197e62c47bc7a3d090479"))
|
||||
(when (featurep! +pretty)
|
||||
(package! org-appear :pin "a4d10fc346ba14f487eb7aa95761b9295089ba55")
|
||||
(package! org-superstar :pin "03be6c0a3081c46a59b108deb8479ee24a6d86c0")
|
||||
(package! org-fancy-priorities :pin "7f677c6c14ecf05eab8e0efbfe7f1b00ae68eb1d"))
|
||||
(when (featurep! +present)
|
||||
(package! centered-window
|
||||
:recipe (:host github :repo "anler/centered-window-mode")
|
||||
:pin "f50859941ab5c7cbeaee410f2d38716252b552ac")
|
||||
(package! org-tree-slide :pin "27f8bb6a9676e1c0b500e75799e3b5c37a9156af")
|
||||
(package! org-re-reveal :pin "55fca47c740c50fe04cbf2b8ae90e02174626c0c")
|
||||
(package! revealjs
|
||||
:recipe (:host github :repo "hakimel/reveal.js"
|
||||
:files ("css" "dist" "js" "plugin"))
|
||||
:pin "a9277f9d465a07cc3b2baa3a2c4fbc152afd7f14"))
|
||||
(cond
|
||||
((featurep! +roam)
|
||||
(package! org-roam
|
||||
:recipe (:host github :repo "org-roam/org-roam-v1")
|
||||
:pin "946a879a4a18756a0508afba1e0b0fe070c6a8b4"))
|
||||
((featurep! +roam2)
|
||||
(package! org-roam
|
||||
;; FIXME A :recipe isn't strictly necessary, but without it, our package
|
||||
;; bumper fails to distinguish between org-roam v1 and v2.
|
||||
:recipe (:host github :repo "org-roam/org-roam")
|
||||
:pin "abe63b436035049923ae96639b9b856697047779")))
|
||||
|
||||
;;; Babel
|
||||
(package! ob-async :pin "9aac486073f5c356ada20e716571be33a350a982")
|
||||
(when (featurep! :lang crystal)
|
||||
(package! ob-crystal :pin "d84c1adee4b269cdba06a97caedb8071561a09af"))
|
||||
(when (featurep! :lang elixir)
|
||||
(package! ob-elixir :pin "8990a8178b2f7bd93504a9ab136622aab6e82e32"))
|
||||
(when (featurep! :lang go)
|
||||
(package! ob-go :pin "2067ed55f4c1d33a43cb3f6948609d240a8915f5"))
|
||||
(when (featurep! :lang hy)
|
||||
(package! ob-hy :pin "a42ecaf440adc03e279afe43ee5ef6093ddd542a"))
|
||||
(when (featurep! :lang nim)
|
||||
(package! ob-nim :pin "6fd060a3ecd38be37e4ec2261cd65760a3c35a91"))
|
||||
(when (featurep! :lang racket)
|
||||
(package! ob-racket
|
||||
:recipe (:host github :repo "DEADB17/ob-racket")
|
||||
:pin "d8fd51bddb019b0eb68755255f88fc800cfe03cb"))
|
||||
(when (featurep! :lang rest)
|
||||
(package! ob-restclient :pin "bfbc4d8e8a348c140f9328542daf5d979f0993e2"))
|
||||
(when (featurep! :lang scala)
|
||||
(package! ob-ammonite :pin "39937dff395e70aff76a4224fa49cf2ec6c57cca"))
|
||||
|
||||
;;; Export
|
||||
(when (featurep! +pandoc)
|
||||
(package! ox-pandoc :pin "eda1f21fd519427c070d165f8a663db07b87ac29"))
|
||||
(when (featurep! +hugo)
|
||||
(package! ox-hugo
|
||||
:recipe (:host github :repo "kaushalmodi/ox-hugo" :nonrecursive t)
|
||||
:pin "88e60681901573797ce53c91ad8fa0936f6e4ee2"))
|
||||
(when (featurep! :lang rst)
|
||||
(package! ox-rst :pin "99fa790da55b57a3f2e9aa187493ba434a64250e"))
|
||||
133
.config/emacs/modules/lang/org/test/test-org.el
Normal file
133
.config/emacs/modules/lang/org/test/test-org.el
Normal file
@@ -0,0 +1,133 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/org/test/test-autoload-org.el
|
||||
|
||||
(describe "lang/org"
|
||||
;; `+org/insert-item'
|
||||
(describe "insert-item"
|
||||
(before-all
|
||||
(require 'org)
|
||||
(load! "../autoload/org.el"))
|
||||
(after-all
|
||||
(unload-feature 'org t))
|
||||
|
||||
(before-each
|
||||
(set-buffer (get-buffer-create "org"))
|
||||
(erase-buffer)
|
||||
(delay-mode-hooks (org-mode)))
|
||||
(after-each
|
||||
(kill-buffer (get-buffer "org")))
|
||||
|
||||
(describe "headlines"
|
||||
(it "opens new headline below"
|
||||
(insert!! "* {0}Header")
|
||||
(+org/insert-item-below 1)
|
||||
(expect (eobp))
|
||||
(expect (buffer-substring-no-properties (point-min) (point-max))
|
||||
:to-equal "* Header\n* "))
|
||||
|
||||
(it "opens new headline above"
|
||||
(insert!! "* {0}Header")
|
||||
(+org/insert-item-above 1)
|
||||
(expect (eolp))
|
||||
(expect (buffer-substring-no-properties (point-min) (point-max))
|
||||
:to-equal "* \n* Header"))
|
||||
|
||||
(it "appends headlines, skipping subtrees"
|
||||
(insert!! "** {0}First\n"
|
||||
"*** sub 1\n"
|
||||
"*** sub 2\n"
|
||||
"**** subsub 1\n"
|
||||
"** Header")
|
||||
(+org/insert-item-below 1)
|
||||
(expect (eolp))
|
||||
(expect (line-number-at-pos) :to-be 5)
|
||||
(expect (buffer-substring-no-properties (point-min) (point-max))
|
||||
:to-equal
|
||||
(string-join '("** First"
|
||||
"*** sub 1"
|
||||
"*** sub 2"
|
||||
"**** subsub 1"
|
||||
"** "
|
||||
"** Header")
|
||||
"\n")))
|
||||
(it "prepends headlines, skipping subtrees"
|
||||
(insert!! "** First\n"
|
||||
"*** sub 1\n"
|
||||
"*** sub 2\n"
|
||||
"**** {0}subsub 1\n"
|
||||
"** Header")
|
||||
(+org/insert-item-above 1)
|
||||
(expect (eolp))
|
||||
(expect (line-number-at-pos) :to-be 4)
|
||||
(expect (buffer-substring-no-properties (point-min) (point-max))
|
||||
:to-equal
|
||||
(string-join '("** First"
|
||||
"*** sub 1"
|
||||
"*** sub 2"
|
||||
"**** "
|
||||
"**** subsub 1"
|
||||
"** Header")
|
||||
"\n"))))
|
||||
|
||||
(describe "plain lists"
|
||||
(it "appends items"
|
||||
(insert!! "+ {0}List item")
|
||||
(+org/insert-item-below 1)
|
||||
(expect (buffer-substring-no-properties (point-min) (point-max))
|
||||
:to-equal "+ List item\n+ "))
|
||||
(it "prepends items"
|
||||
(insert!! "+ {0}List item")
|
||||
(+org/insert-item-above 1)
|
||||
(expect (buffer-substring-no-properties (point-min) (point-max))
|
||||
:to-equal "+ \n+ List item"))
|
||||
|
||||
(it "appends items, but skips over child items"
|
||||
(insert!! "+ {0}List item\n"
|
||||
" + Sub item\n"
|
||||
"+ List item")
|
||||
(+org/insert-item-below 1)
|
||||
(expect (buffer-substring-no-properties (point-min) (point-max))
|
||||
:to-equal
|
||||
(string-join '("+ List item"
|
||||
" + Sub item"
|
||||
"+ "
|
||||
"+ List item")
|
||||
"\n")))
|
||||
(it "prepends items, but skips over child items"
|
||||
(insert!! "+ List item\n"
|
||||
" + Sub item\n"
|
||||
"+ {0}List item")
|
||||
(+org/insert-item-above 1)
|
||||
(expect (buffer-substring-no-properties (point-min) (point-max))
|
||||
:to-equal
|
||||
(string-join '("+ List item"
|
||||
" + Sub item"
|
||||
"+ "
|
||||
"+ List item")
|
||||
"\n"))))
|
||||
|
||||
(describe "numbered lists"
|
||||
(it "appends items and updates numbers"
|
||||
(insert!! "1. {0}List item\n"
|
||||
"2. Sub item\n"
|
||||
"3. List item")
|
||||
(+org/insert-item-below 1)
|
||||
(expect (buffer-substring-no-properties (point-min) (point-max))
|
||||
:to-equal
|
||||
(string-join '("1. List item"
|
||||
"2. "
|
||||
"3. Sub item"
|
||||
"4. List item")
|
||||
"\n")))
|
||||
(it "prepends items and updates numbers"
|
||||
(insert!! "1. List item\n"
|
||||
"2. Sub item\n"
|
||||
"3. {0}List item")
|
||||
(+org/insert-item-above 1)
|
||||
(expect (buffer-substring-no-properties (point-min) (point-max))
|
||||
:to-equal
|
||||
(string-join '("1. List item"
|
||||
"2. Sub item"
|
||||
"3. "
|
||||
"4. List item")
|
||||
"\n"))))))
|
||||
Reference in New Issue
Block a user