branch: externals/org-remark commit 51c3d91585ee12353f83b3ce9b823932f3f515ad Author: Noboru Ota <m...@nobiot.com> Commit: Noboru Ota <m...@nobiot.com>
refactor: create macro & menus The `org-remark-create` macro has been changed to include the line-highlight pen. This means that if the user creates pens in their init file and compile it, they would need to recompile it. --- org-remark-line.el | 26 ++++++++++++++----------- org-remark.el | 57 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/org-remark-line.el b/org-remark-line.el index 20100ea936..c436738321 100644 --- a/org-remark-line.el +++ b/org-remark-line.el @@ -5,7 +5,7 @@ ;; Author: Noboru Ota <m...@nobiot.com> ;; URL: https://github.com/nobiot/org-remark ;; Created: 01 August 2023 -;; Last modified: 03 August 2023 +;; Last modified: 04 August 2023 ;; Package-Requires: ((emacs "27.1") (org "9.4")) ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp @@ -28,7 +28,7 @@ ;;; Code: -;;(require 'org-remark) +(require 'org-remark) (defface org-remark-line-highlighter '((((class color) (min-colors 88) (background light)) @@ -76,15 +76,19 @@ by `overlays-in'." (set-window-margins nil 2))) ;;;###autoload -(defun org-remark-mark-line (beg end &optional id mode) - (interactive (org-remark-beg-end 'line)) - (org-remark-highlight-mark beg end id mode ;; LINE line function different - ;; LINE needs to be the suffix of a - ;; function: `org-remark-mark-' - "line" nil ;; LINE important to put - ;; the suffix of the label - ;; to call this correct function - (list 'org-remark-type 'line))) +;; (defun org-remark-mark-line (beg end &optional id mode) +;; (interactive (org-remark-beg-end 'line)) +;; (org-remark-highlight-mark beg end id mode ;; LINE line function different +;; ;; LINE needs to be the suffix of a +;; ;; function: `org-remark-mark-' +;; "line" nil ;; LINE important to put +;; ;; the suffix of the label +;; ;; to call this correct function +;; (list 'org-remark-type 'line))) + +(org-remark-create "line" + 'org-remark-line-highlighter + '(org-remark-type line)) (cl-defmethod org-remark-beg-end ((org-remark-type (eql 'line))) (let ((bol (org-remark-line-pos-bol (point)))) diff --git a/org-remark.el b/org-remark.el index d395ef9a4d..84679aabcf 100644 --- a/org-remark.el +++ b/org-remark.el @@ -1,4 +1,4 @@ - ;;; org-remark.el --- Highlight & annotate any text files -*- lexical-binding: t; -*- +;;; org-remark.el --- Highlight & annotate any text files -*- lexical-binding: t; -*- ;; Copyright (C) 2020-2023 Free Software Foundation, Inc. @@ -6,7 +6,7 @@ ;; URL: https://github.com/nobiot/org-remark ;; Version: 1.1.0 ;; Created: 22 December 2020 -;; Last modified: 03 August 2023 +;; Last modified: 05 August 2023 ;; Package-Requires: ((emacs "27.1") (org "9.4")) ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp, @@ -198,7 +198,6 @@ add additional controls for the overlay properties") ;;;; Macros to create user-defined highlighter pen functions - (defmacro org-remark-create (label &optional face properties) "Create and register new highlighter pen functions. @@ -247,7 +246,8 @@ highlight. In this case, no new ID gets generated. When the pen itself defines the help-echo property, it will have the priority over the excerpt of the marginal notes." (or face "`org-remark-highlighter'") properties) - (interactive (org-remark-region-or-word)) + (interactive (org-remark-beg-end + (quote ,(plist-get (eval properties) 'org-remark-type)))) (org-remark-highlight-mark beg end id mode ,label ,face ,properties)) ;; Register to `org-remark-available-pens' @@ -266,7 +266,9 @@ the priority over the excerpt of the marginal notes." (lambda () (interactive) (org-remark-change - #',(intern (format "org-remark-mark-%s" label))))))))) + #',(intern (format "org-remark-mark-%s" label)))) + :enable (org-remark-pen-same-type-at-point-p + (quote ,(plist-get (eval properties) 'org-remark-type)))))))) ;;;; Minor mode @@ -340,35 +342,42 @@ recommended to turn it on as part of Emacs initialization. (define-key-after org-remark-menu-map [org-remark-open] '(menu-item "Open" org-remark-open - :help "Display and move to marginal notes for highlight at point")) + :help "Display and move to marginal notes for highlight at point" + :enable (org-remark-find-dwim))) (define-key-after org-remark-menu-map [org-remark-view] '(menu-item "View" org-remark-view - :help "Display marginal notes for highlight at point; stay in current buffer")) + :help "Display marginal notes for highlight at point; stay in current buffer" + :enable (org-remark-find-dwim))) (define-key-after org-remark-menu-map [org-remark-view-next] - '(menu-item "View next" org-remark-view-next)) + '(menu-item "View next" org-remark-view-next + :enable org-remark-highlights)) (define-key-after org-remark-menu-map [org-remark-view-prev] - '(menu-item "View previous" org-remark-view-prev)) + '(menu-item "View previous" org-remark-view-prev + :enable org-remark-highlights)) (define-key-after org-remark-menu-map [org-remark-toggle] '(menu-item "Toggle" org-remark-toggle - :help "Toggle showing/hiding of highlights in current buffer")) + :help "Toggle showing/hiding of highlights in current buffer" + :enable org-remark-highlights)) (define-key-after org-remark-menu-map [org-remark-remove] '(menu-item "Remove" org-remark-remove - :help "Remove highlight at point, keeping the marginal notes entry")) + :help "Remove highlight at point, keeping the marginal notes entry" + :enable (org-remark-find-dwim))) (define-key-after org-remark-menu-map [org-remark-delete] '(menu-item "Delete" org-remark-delete - :help "Delete highlight at point and the marginal notes entry")) + :help "Delete highlight at point and the marginal notes entry" + :enable (org-remark-find-dwim))) ;; Make pen functions menu (defvar org-remark-pen-map @@ -384,15 +393,18 @@ recommended to turn it on as part of Emacs initialization. (define-key-after org-remark-change-pen-map [org-remark-change] - '(menu-item "default pen" (lambda () - (interactive) - (org-remark-change #'org-remark-mark)))) + '(menu-item "default pen" + (lambda () + (interactive) + (org-remark-change #'org-remark-mark)) + :enable (org-remark-pen-same-type-at-point-p nil))) ;; Add change menu to the parent menu (define-key-after org-remark-menu-map [org-remark-change-pens] - (list 'menu-item "Change to..." org-remark-change-pen-map) - 'org-remark-toggle) + `(menu-item "Change to..." ,org-remark-change-pen-map + :enable (org-remark-find-dwim) + 'org-remark-toggle)) ;; Add pen menu to the parent menu (define-key org-remark-menu-map @@ -404,6 +416,11 @@ recommended to turn it on as part of Emacs initialization. [menu-bar org-remark] (list 'menu-item "Org-remark" org-remark-menu-map)) +(defun org-remark-pen-same-type-at-point-p (org-remark-type) + "Return t if the highlight's type is the same as ORG-REMARK-TYPE." + (eql org-remark-type + (overlay-get (org-remark-find-dwim (point)) 'org-remark-type))) + ;;;; Commands @@ -1653,12 +1670,6 @@ If FILENAME is nil, return nil." (with-current-buffer (find-file-noselect (org-remark-notes-get-file-name)) (funcall org-remark-source-file-name filename)))) -;; (defvar org-remark-beg-end-dwim-functions '(org-remark-region-or-word)) - -;; (defun org-remark-beg-end-dwim () -;; (run-hook-with-args-until-success -;; 'org-remark-beg-end-dwim-functions)) - (cl-defgeneric org-remark-beg-end (_org-remark-type) (org-remark-region-or-word))