um--set-cursor-intangible-property : dont fuck with buffer-modified-p status

This commit is contained in:
bth 2026-07-05 10:03:13 -07:00
commit 0b2c8c3e33

28
um.el
View file

@ -563,11 +563,28 @@ A negative prefix argument moves it backward.
(defun um-previous-line () (defun um-previous-line ()
(interactive) (move-beginning-of-line nil) (previous-line)) (interactive) (move-beginning-of-line nil) (previous-line))
(defun um--set-cursor-intangible-property ()
(let ((modified (buffer-modified-p)))
(save-excursion
(goto-char (point-min))
(while (not (eobp))
;; NOTE: reset all properties as side-effect. But this is what we want.
;; NOTE: actually the newline is the only position not included, but this
;; positions the cursor visually at the bol:
(set-text-properties (pos-bol) (pos-eol) '(cursor-intangible t))
(forward-line 1)))
;; we don't want to fuck with the modified state just to change text
;; properties, but we also don't want to obscure it if it was already modified.
(set-buffer-modified-p modified)))
(defun um--iro (cmd &optional args) (defun um--iro (cmd &optional args)
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(apply cmd args))) (apply cmd args)
;; NOTE: every modification of buffer needs to reset the props:
(um--set-cursor-intangible-property)))
(defun um-drag-stuff-up () (interactive) (um--iro 'drag-stuff-up '(1))) (defun um-drag-stuff-up () (interactive) (um--iro 'drag-stuff-up '(1)))
;; TODO: drag-stuff-down is breaking um--set-cursor-intangible-property
(defun um-drag-stuff-down () (interactive) (um--iro 'drag-stuff-down '(1))) (defun um-drag-stuff-down () (interactive) (um--iro 'drag-stuff-down '(1)))
(defun um-kill-line () (interactive) (um--iro 'kill-line)) (defun um-kill-line () (interactive) (um--iro 'kill-line))
(defun um-kill-region () (interactive) (um--iro 'kill-region '(nil nil t))) (defun um-kill-region () (interactive) (um--iro 'kill-region '(nil nil t)))
@ -600,15 +617,8 @@ A negative prefix argument moves it backward.
\\{um-mode-map} \\{um-mode-map}
" "
;; restrict movement to (bolp) with cursor-intangible-mode
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(save-excursion (um--set-cursor-intangible-property))
(goto-char (point-min))
(while (not (eobp))
;; NOTE: actually the newline is the only position not included, but this
;; positions the cursor visually at the bol:
(put-text-property (pos-bol) (pos-eol) 'cursor-intangible t)
(forward-line 1))))
(cursor-intangible-mode) (cursor-intangible-mode)
(read-only-mode)) (read-only-mode))