[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-remark b988d580d8 090/173: add: Create pen to have
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-remark b988d580d8 090/173: add: Create pen to have different colors |
Date: |
Fri, 28 Jan 2022 16:58:04 -0500 (EST) |
branch: externals/org-remark
commit b988d580d8ffcda2bb0cb57249d9bbac41f0a73a
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>
add: Create pen to have different colors
---
org-marginalia.el | 91 +++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 79 insertions(+), 12 deletions(-)
diff --git a/org-marginalia.el b/org-marginalia.el
index b4750f1b9e..27f7ab19b3 100644
--- a/org-marginalia.el
+++ b/org-marginalia.el
@@ -93,6 +93,51 @@ It is meant to exist only one of these in each Emacs
session.")
(defconst org-marginalia-prop-source-beg "marginalia-source-beg")
(defconst org-marginalia-prop-source-end "marginalia-source-end")
+;;; Macros
+(defmacro org-marginalia-make-pen (label face &rest properties)
+ "Create a user-defined highlight function.
+LABEL is the name of the highlight. The function will be called
+`ov-highlight-LABEL', and it will apply FACE to the selected
+region. FACE can be an anonymous face, or a function that returns
+one. PROPERTIES is a list of symbols and properties. If the
+property is a function, it will be evaluated. The function takes
+no arguments."
+ `(defun ,(intern (format "org-marginalia-mark-%s" label)) (beg end &optional
id)
+ ,(format "Apply the face %S to the region selected by BEG and END" face)
+ (interactive "r")
+ ;; (flyspell-delete-region-overlays beg end)
+ (unless org-marginalia-mode (org-marginalia-mode +1))
+ ;; UUID is too long; does not have to be the full length
+ (when (not id) (setq id (substring (org-id-uuid) 0 8)))
+ ;; Add highlight to the text
+ (org-with-wide-buffer
+ (let ((face ,face)
+ (properties (quote ,properties))
+ (ov (make-overlay beg end nil 'FRONT-ADVANCE)))
+ (overlay-put ov 'face face)
+ (while properties
+ (setq prop (pop properties)
+ val (pop properties))
+ (overlay-put ov prop val))
+ (overlay-put ov 'org-marginalia-id id)
+ ;; Keep track it in a local variable. It's a list overlays, guranteed
to
+ ;; contain only marginalia overlays as opposed to the one returned by
+ ;; `overlay-lists'
+ ;; TODO Do we need to consider this for overlay?
+ ;; `set-marker-insertion-type' to
+ ;; set the type t is necessary to move the cursor in sync with the
+ ;; font-lock-face property of the text property.
+ (push ov org-marginalia-highlights)
+ ;; Adding overlay does not set the buffer modified.
+ ;; It's more fluid with save operation.
+ ;; You cannot use `undo' to undo highlighter.
+ (deactivate-mark)
+ (unless (buffer-modified-p) (set-buffer-modified-p t))))
+ (org-marginalia-housekeep)
+ (org-marginalia-sort-highlights-list)))
+
+(org-marginalia-make-pen "yellow" '(:background "Yellow") "category"
"important" "org-marginalia-label" "yellow")
+
;;;; Commands
;;;###autoload
@@ -417,9 +462,9 @@ are still recorded in the marginalia file."
;;;;; Private
-(defun org-marginalia-save-single-highlight (highlight title source-path orgid)
+(defun org-marginalia-save-single-highlight (highlight title path orgid)
"Save a single HIGHLIGHT in the marginalia file with properties.
-The marginalia file is specified by SOURCE-PATH. If headline with
+The marginalia file is specified by PATH. If headline with
the same ID already exists, update it based on the new highlight
position and highlighted text as TITLE. If it is a new highlight,
create a new headline at the end of the buffer.
@@ -437,7 +482,18 @@ backlink feature for marginalia files."
(end (overlay-end highlight))
(id (overlay-get highlight 'org-marginalia-id))
;;`org-with-wide-buffer is a macro that should work for non-Org file'
- (text (org-with-wide-buffer (buffer-substring-no-properties beg
end))))
+ (text (org-with-wide-buffer (buffer-substring-no-properties beg end)))
+ (props (overlay-properties highlight))
+ (note-props nil))
+ (while props
+ (let ((p (pop props))
+ (v (pop props)))
+ (when (and (stringp p)
+ (or (string-equal "category" (downcase p))
+ (and (>= (length p) 15)
+ (string-equal "org-marginalia-" (downcase
(substring p 0 15))))))
+ (push v note-props)
+ (push p note-props))))
;; TODO Want to add a check if save is applicable here.
(with-current-buffer (find-file-noselect org-marginalia-notes-file-path)
;; If it is a new empty marginalia file
@@ -445,7 +501,7 @@ backlink feature for marginalia files."
(org-id-get-create))
(org-with-wide-buffer
(let ((file-headline (org-find-property
- org-marginalia-prop-source-file source-path))
+ org-marginalia-prop-source-file path))
(id-headline (org-find-property org-marginalia-prop-id id)))
(unless file-headline
;; If file-headline does not exist, create one at the bottom
@@ -453,18 +509,19 @@ backlink feature for marginalia files."
;; Ensure to be in the beginning of line to add a new headline
(when (eolp) (open-line 1) (forward-line 1) (beginning-of-line))
(insert (concat "* " title "\n"))
- (org-set-property org-marginalia-prop-source-file source-path))
+ (org-set-property org-marginalia-prop-source-file path))
(cond (id-headline
(goto-char id-headline)
;; Update the existing headline and position properties
(org-edit-headline text)
+ (org-marginalia-notes-set-properties nil beg end note-props)
(org-set-property org-marginalia-prop-source-beg
(number-to-string beg))
(org-set-property org-marginalia-prop-source-end
(number-to-string end)))
(t ;; No headline with the ID property. Create one
(when-let ((p (org-find-property
- org-marginalia-prop-source-file source-path)))
+ org-marginalia-prop-source-file path)))
(goto-char p))
(org-narrow-to-subtree)
(goto-char (point-max))
@@ -473,16 +530,26 @@ backlink feature for marginalia files."
;; Create a headline
;; Add a properties
(insert (concat "** " text "\n"))
- (org-set-property org-marginalia-prop-id id)
- (org-set-property org-marginalia-prop-source-beg
- (number-to-string beg))
- (org-set-property org-marginalia-prop-source-end
- (number-to-string end))
+ (org-marginalia-notes-set-properties id beg end note-props)
(if (and org-marginalia-use-org-id orgid)
(insert (concat "[[id:" orgid "]" "[" title "]]"))
- (insert (concat "[[file:" source-path "]" "[" title
"]]")))))))
+ (insert (concat "[[file:" path "]" "[" title "]]")))))))
(when (buffer-modified-p) (save-buffer) t))))
+(defun org-marginalia-notes-set-properties (id beg end &optional props)
+ "."
+ (when id (org-set-property org-marginalia-prop-id id))
+ (org-set-property org-marginalia-prop-source-beg
+ (number-to-string beg))
+ (org-set-property org-marginalia-prop-source-end
+ (number-to-string end))
+ (while props
+ ;; Upcase for the property names for Org It seems CATEGORY needs to be
+ ;; uppercase for sparse tree search to work properly.
+ (let ((p (upcase (pop props)))
+ (v (pop props)))
+ (org-set-property p v))))
+
(defun org-marginalia-list-highlights-positions (&optional reverse)
"Return list of beg points of highlights in this buffer.
By default, the list is in ascending order.
- [elpa] externals/org-remark 1ce0a7dc31 061/173: add: org-marginalia-remove can take C-u to delete, (continued)
- [elpa] externals/org-remark 1ce0a7dc31 061/173: add: org-marginalia-remove can take C-u to delete, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark e4927186ef 063/173: feat: global auto-tracking, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark b62c6b3de4 072/173: readme, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 6b0bbad4b3 070/173: feat: link with org-id (WIP), ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark a9acfcd106 077/173: doc: README for 0.0.6, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 57bd3ab847 078/173: add: tracking-save to local kill-buffer-hook, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark c1adffe077 082/173: docs: 0.0.6 docs, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 60cbbc4e99 083/173: Merge dev/0.0.6-revise, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 2d11de2ec2 085/173: docs: README, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 3037be5ebc 087/173: docs: update README with global-tracking-mode, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark b988d580d8 090/173: add: Create pen to have different colors,
ELPA Syncer <=
- [elpa] externals/org-remark 02d7b56265 088/173: fix: tracking does not save for the first file, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 7242c83d8f 094/173: copyright year, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark f988330790 091/173: add: make-pen props work as intended, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark bdbde4eda8 093/173: refactor: macro to make different pen, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark b3a8e3e2ec 097/173: add: Org-HANA: Org to Highlight & ANnotate Any text file (HANA), ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark f7e796cd6b 095/173: chg: don't update headline text; various refactors, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 4ee9e23e50 100/173: intrnl: refactor fn names, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark ecb82aebbe 101/173: intrnl correct some minor errors, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark fd5cab5ac2 102/173: rm: org-marginalia*.el, ELPA Syncer, 2022/01/28
- [elpa] externals/org-remark 51b0c08f25 104/173: docs: NEWS, README etc. for name change, ELPA Syncer, 2022/01/28