From 5cce6c503523cd144dc021811a2f0abcfdde28a3 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 13 Feb 2020 14:21:04 -0500 Subject: [PATCH] Hack Deft to respect #+TITLE file properties --- emacs/init.org | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/emacs/init.org b/emacs/init.org index 860b787..45fdbbe 100755 --- a/emacs/init.org +++ b/emacs/init.org @@ -95,10 +95,11 @@ Load [[https://github.com/raxod502/straight.el][straight.el]] to manage package #+END_SRC * Load org mode -Load org-mode early to [[https://github.com/raxod502/straight.el#the-wrong-version-of-my-package-was-loaded][avoid a version clash]] (but don't load it if the bootstrap file already did): +Load org-mode early to [[https://github.com/raxod502/straight.el#the-wrong-version-of-my-package-was-loaded][avoid a version clash]]. #+BEGIN_SRC emacs-lisp (use-package org :straight org-plus-contrib + :commands (org-element-map) :mode (("\\.org\\'" . org-mode))) #+END_SRC @@ -1873,6 +1874,24 @@ Integrate Google calendar with org-mode: (general-def '(normal motion) org-agenda-mode-map "gr" #'org-agenda-redo-and-fetch-gcal) #+END_SRC +** Utilities +A function to get the TITLE property of the current org buffer: +#+BEGIN_SRC emacs-lisp + (defun org-get-title (&optional contents) + (let ((raw (or contents + (buffer-substring (point-min) (point-max))))) + (with-temp-buffer + (insert raw) + (car + (org-element-map + (org-element-parse-buffer) + 'keyword + (lambda (el) + (when (string-match-p "TITLE" + (org-element-property :key el)) + (org-element-property :value el)))))))) +#+END_SRC + * link-hint A very helpful package that provides jump-to-link functionality: #+BEGIN_SRC emacs-lisp @@ -2533,7 +2552,6 @@ Run black on the current buffer: (append autoflake-args (list "--in-place" file))))) #+END_SRC - * Hy Python but Lispy! @@ -4802,6 +4820,18 @@ A fuzzy-finder for notes. (leader-def-key "D" #'deft) #+END_SRC +Tell Deft to use the TITLE property for entry titles, if it exists: +#+BEGIN_SRC emacs-lisp + (with-eval-after-load 'deft + (advice-add + 'deft-parse-title :around + (lambda (old-fn file contents &rest args) + (let ((title (org-get-title contents))) + (if title + title + (apply old-fn file contents args)))))) +#+END_SRC + * Pollen #+BEGIN_SRC emacs-lisp (use-package pollen-mode