Ignore direct input when at the start of an Org headline

This is to guard headlines to become invalid due to my erratic (mis)typing behavior.
This commit is contained in:
Daniel Borchmann 2025-04-19 16:53:04 +02:00
parent def778595d
commit 837b7fc106
No known key found for this signature in database
GPG Key ID: 50EA937BF472ADD1
2 changed files with 27 additions and 5 deletions

14
init.el
View File

@ -646,6 +646,7 @@
db/org-execute-babel-in-buffer-and-iterate-tables db/org-execute-babel-in-buffer-and-iterate-tables
db/make-org-capture-frame db/make-org-capture-frame
db/org-cleanup-continuous-clocks db/org-cleanup-continuous-clocks
db/org-update-headline-log-note
db/find-csv-in-org db/find-csv-in-org
db/export-diary db/export-diary
db/org-insert-checklist db/org-insert-checklist
@ -675,6 +676,7 @@
db/org-mark-current-default-task db/org-mark-current-default-task
db/org-clocktable-write-with-threshold db/org-clocktable-write-with-threshold
org-dblock-write:db/org-backlinks org-dblock-write:db/org-backlinks
db/org-ignore-insert-on-headline-start
org-password-manager-get-password-by-id org-password-manager-get-password-by-id
db/org-bookmark-open db/org-bookmark-open
db/org-bookmark-store-link db/org-bookmark-store-link
@ -744,10 +746,9 @@
"%80ITEM(Task) %10Effort(Effort) %10CLOCKSUM" "%80ITEM(Task) %10Effort(Effort) %10CLOCKSUM"
;; We activate speed keys primarily to avoid invalidating headlines by accidentally ;; We activate speed keys primarily to avoid invalidating headlines by accidentally
;; typing non-star characters when at the start of a headline. ;; typing non-star characters when at the start of a headline. See
org-use-speed-commands #'(lambda () ;; `db/org-ignore-insert-on-headline-start'.
(and (looking-at org-outline-regexp) org-use-speed-commands t)
(looking-back "^\\**" nil))))
;; Keywords and Tags ;; Keywords and Tags
@ -920,7 +921,10 @@
;; Completely redo agenda buffer when jumping to today; this ensures that agenda views ;; Completely redo agenda buffer when jumping to today; this ensures that agenda views
;; from previous days get updated as expected. ;; from previous days get updated as expected.
(define-advice org-agenda-goto-today (:before () redo-all) (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 (use-package org-cycle
:autoload (org-cycle-hide-drawers) :autoload (org-cycle-hide-drawers)

View File

@ -1243,6 +1243,24 @@ cache if that's in use."
(when (derived-mode-p 'org-agenda-mode) (when (derived-mode-p 'org-agenda-mode)
(org-agenda-redo))) (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) (defun org-password-manager-get-password-by-id (id &optional return-as-value)
"Retrieve password from Org item identified by ID. "Retrieve password from Org item identified by ID.