From e750cd2204108b1f8e7c012ee007682ef8f1df85 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Wed, 17 Mar 2021 13:07:42 +0100 Subject: Replace the minor mode keymap with a local keymap on nroam sections Instead of installing a keymap that overrides orgmode commands, use a sparse keymap only on nroam sections. * nroam.el (nroam-sections-map): New keymap for nroam sections. (with-nroam-markers): Put the new keymap in an overlay on nroam sections. (nroam-ctrl-c-ctrl-c): Remove unused function. (nroam-return): (nroam-update): Do not fallback to org commands anymore. --- nroam.el | 53 +++++++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) (limited to 'nroam.el') diff --git a/nroam.el b/nroam.el index dbe3cde..6900d08 100644 --- a/nroam.el +++ b/nroam.el @@ -49,6 +49,13 @@ :group 'nroam :type '(repeat function)) +(defvar nroam-sections-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-c C-c") #'nroam-update) + (define-key map (kbd "RET") #'nroam-return) + map) + "Local keymap within nroam sections.") + (defun nroam-register-section (function) "Add FUNCTION as a section in nroam." (add-to-list 'nroam-sections function t)) @@ -64,20 +71,16 @@ Make the region inserted by BODY read-only, and marked with `(let ((beg (point))) (set-marker nroam-start-marker (point)) ,@body - (put-text-property beg (1+ beg) 'front-sticky '(read-only)) - (put-text-property beg (point) 'read-only t) - ;; Add a non-read-only newline so that text can be inserted at the end of - ;; the buffer. - (let ((inhibit-read-only t)) + (let* ((end (point)) + (ov (make-overlay beg end))) + (overlay-put ov 'keymap nroam-sections-map) + (put-text-property beg (1+ beg) 'front-sticky '(read-only)) + (put-text-property beg end 'read-only t) + ;; Add a non-read-only newline so that text can be inserted at the end of + ;; the buffer. (insert "\n")) (set-marker nroam-end-marker (point)))) -(defvar nroam-mode-map - (let ((map (make-sparse-keymap))) - (define-key map (kbd "C-c C-c") #'nroam-ctrl-c-ctrl-c) - (define-key map (kbd "RET") #'nroam-return) - map)) - ;;;###autoload (defun nroam-setup-maybe () "Setup nroam for the current buffer iff an `org-roam' buffer." @@ -88,7 +91,6 @@ Make the region inserted by BODY read-only, and marked with (define-minor-mode nroam-mode "Show nroam sections at the end of org-roam buffers." :lighter " nroam" - :keymap nroam-mode-map (if nroam-mode (progn (add-hook 'before-save-hook #'nroam--prune nil t) @@ -103,27 +105,17 @@ Make the region inserted by BODY read-only, and marked with (when (file-exists-p buffer-file-name) (nroam-update))) -;;;###autoload -(defun nroam-ctrl-c-ctrl-c () - "Update the sections for the current buffer, or fallback to `org-ctrl-c-ctrl-c'." - (interactive) - (if (nroam--point-at-section-p) - (nroam-update) - (call-interactively (if org-capture-mode - #'org-capture-finalize - #'org-ctrl-c-ctrl-c)))) - ;;;###autoload (defun nroam-return () - "Open nroam link at point, or fallback to `org-return'." + "Open nroam link or push button at point." (interactive) - (if (nroam--point-at-section-p) - (nroam--follow-link) - (call-interactively #'org-return))) + (if (get-text-property (point) 'button) + (call-interactively #'push-button) + (nroam--follow-link))) ;;;###autoload (defun nroam-update () - "Update `org-roam' sections for the current buffer." + "Update nroam sections for the current buffer." (interactive) (nroam--setup-markers) (nroam--prune) @@ -133,13 +125,6 @@ Make the region inserted by BODY read-only, and marked with "Return non-nil if the current buffer is an `org-roam' buffer." (org-roam--org-roam-file-p)) -(defun nroam--point-at-section-p () - "Return non-hil if point if on the backlinks section." - (when (nroam--sections-inserted-p) - (when-let* ((beg (marker-position nroam-start-marker)) - (end (marker-position nroam-end-marker))) - (<= beg (point) end)))) - (defun nroam--update-maybe () "Update backlinks when nroam is enabled." (when nroam-mode -- cgit v1.2.3-54-g00ecf