diff --git a/init.el b/init.el index 1bc282b..c28b1a7 100644 --- a/init.el +++ b/init.el @@ -646,6 +646,7 @@ db/org-execute-babel-in-buffer-and-iterate-tables db/make-org-capture-frame db/org-cleanup-continuous-clocks + db/org-update-headline-log-note db/find-csv-in-org db/export-diary db/org-insert-checklist @@ -675,6 +676,7 @@ db/org-mark-current-default-task db/org-clocktable-write-with-threshold org-dblock-write:db/org-backlinks + db/org-ignore-insert-on-headline-start org-password-manager-get-password-by-id db/org-bookmark-open db/org-bookmark-store-link @@ -744,10 +746,9 @@ "%80ITEM(Task) %10Effort(Effort) %10CLOCKSUM" ;; We activate speed keys primarily to avoid invalidating headlines by accidentally - ;; typing non-star characters when at the start of a headline. - org-use-speed-commands #'(lambda () - (and (looking-at org-outline-regexp) - (looking-back "^\\**" nil)))) + ;; typing non-star characters when at the start of a headline. See + ;; `db/org-ignore-insert-on-headline-start'. + org-use-speed-commands t) ;; Keywords and Tags @@ -920,7 +921,10 @@ ;; Completely redo agenda buffer when jumping to today; this ensures that agenda views ;; from previous days get updated as expected. (define-advice org-agenda-goto-today (:before () redo-all) - (org-agenda-redo-all)))) + (org-agenda-redo-all)) + + ;; Inhibit direct input when point is at the beginning of a headline. + (add-to-list 'org-speed-command-hook 'db/org-ignore-insert-on-headline-start))) (use-package org-cycle :autoload (org-cycle-hide-drawers) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 51cbff6..0a6bc54 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -1243,6 +1243,24 @@ cache if that's in use." (when (derived-mode-p 'org-agenda-mode) (org-agenda-redo))) +(defun db/org-ignore-insert-on-headline-start (keys) + "Return an error function when point is at the start of a headline. + +Point is at the start of a headline when it is at or before the first +space that separates the stars from the title of the headline. + +This function is meant to be added to `org-speed-command-hook'. KEYS is +ignored. + +The implementat has been adapted from `org-speed-command-activate' to +ignore all keys pressed at the beginning of a headline." + (ignore keys) + (when (and (or (looking-at "\\*") + (looking-at " ")) + (looking-back "^\\** ?" nil)) + #'(lambda () + (user-error "No direct input allowed in headline")))) + (defun org-password-manager-get-password-by-id (id &optional return-as-value) "Retrieve password from Org item identified by ID.