[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-remark ded8fddddd 01/75: initial prototype to explo
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-remark ded8fddddd 01/75: initial prototype to explore what needs to change |
Date: |
Fri, 6 Oct 2023 12:59:15 -0400 (EDT) |
branch: externals/org-remark
commit ded8fddddddd90d7f9dd813b2839f5ce17fe69dc
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>
initial prototype to explore what needs to change
---
org-remark-line-highlighter.el | 125 +++++++++++++++++++++++++++++++++++++++++
org-remark.el | 12 ++--
2 files changed, 133 insertions(+), 4 deletions(-)
diff --git a/org-remark-line-highlighter.el b/org-remark-line-highlighter.el
new file mode 100644
index 0000000000..134af3104a
--- /dev/null
+++ b/org-remark-line-highlighter.el
@@ -0,0 +1,125 @@
+;;; org-remark-line.el --- Enable Org-roam to highlight a line -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2021-2023 Free Software Foundation, Inc.
+
+;; Author: Noboru Ota <me@nobiot.com>
+;; URL: https://github.com/nobiot/org-remark
+;; Created: 01 August 2023
+;; Last modified: 01 August 2023
+;; Package-Requires: ((emacs "27.1") (org "9.4"))
+;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or (at
+;; your option) any later version.
+
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(defun my/test-margin-left ()
+ (interactive)
+ (let* ((ov (make-overlay (line-beginning-position)
(line-beginning-position)))
+ (left-margin (or (car (window-margins))
+ ;; when nil = no margin, set to 1
+ (progn (set-window-margins nil 2)
+ 2)))
+ (spaces (- left-margin 2))
+ (string (with-temp-buffer (insert-char ?\s spaces)
+ (insert "‣ ")
+ (buffer-string))))
+ (overlay-put ov 'before-string (propertize "! " 'display
+ `((margin left-margin)
+ ,(propertize string 'face
'modus-themes-markup-code))))))
+
+(defun test/get-beginning-of-line (pos)
+ "Return the beginning of the line position for POS."
+ (save-excursion
+ (goto-char pos)
+ (pos-bol)))
+
+
+(defun test/overlay-put-line-highlight (ov)
+ (let* ((left-margin (or (car (window-margins))
+ ;; when nil = no margin, set to 1
+ (progn (set-window-margins nil 2)
+ 2)))
+ (spaces (- left-margin 2))
+ (string (with-temp-buffer (insert-char ?\s spaces)
+ (insert " ")
+ (buffer-string))))
+ (overlay-put ov 'before-string (propertize "! " 'display
+ `((margin left-margin)
+ ,(propertize string 'face
'modus-themes-diff-refine-removed))))
+ ;;(overlay-put ov 'category "org-remark-line") ;; need to fix property add
logic
+ ov))
+
+;;;###autoload
+(defun org-remark-mark-line (beg end &optional id mode)
+ (interactive (org-remark-region-or-word))
+ (org-remark-line-highlight-mark beg end id mode
+ "line" nil ;; LINE needs to be the suffix of
a function: `org-remark-mark-'
+ (list 'org-remark-type "line")))
+
+(defun org-remark-line-highlight-mark
+ (beg end &optional id mode label face properties)
+ "Apply the FACE to the whole line that contains BEG."
+ ;; Ensure to turn on the local minor mode
+ (unless org-remark-mode (org-remark-mode +1))
+ ;; When highlights are toggled hidden, only the new one gets highlighted in
+ ;; the wrong toggle state.
+ (when org-remark-highlights-hidden (org-remark-highlights-show))
+ (let ((ov (make-overlay (test/get-beginning-of-line beg)
(test/get-beginning-of-line beg))) ;; LINE without :front-advance
+ ;; UUID is too long; does not have to be the full length
+ (id (if id id (substring (org-id-uuid) 0 8)))
+ (filename (org-remark-source-find-file-name)))
+ (if (not filename)
+ (message (format "org-remark: Highlights not saved.\
+ This buffer (%s) is not supported" (symbol-name major-mode)))
+ (org-with-wide-buffer
+ ;;(overlay-put ov 'face (if face face 'org-remark-highlighter)) ;; LINE
+ (test/overlay-put-line-highlight ov) ;; LINE
+ (while properties ;; LINE add prop to indicate it is a line highlighter
+ (let ((prop (pop properties))
+ (val (pop properties)))
+ (overlay-put ov prop val)))
+ (when label (overlay-put ov 'org-remark-label label)) ;; LINE put a
label for line (allow variations)
+ (overlay-put ov 'org-remark-id id)
+ ;; Keep track of the overlay in a local variable. It's a list that is
+ ;; guaranteed to contain only org-remark overlays as opposed to the one
+ ;; returned by `overlay-lists' that lists all overlays.
+ (push ov org-remark-highlights)
+ ;; for mode, nil and :change result in saving the highlight. :load
+ ;; bypasses save.
+ (unless (eq mode :load)
+ (let* ((notes-buf (find-file-noselect
+ (org-remark-notes-get-file-name)))
+ (source-buf (current-buffer))
+ ;; Get props for create and change modes
+ (notes-props
+ (org-remark-highlight-add ov source-buf notes-buf)))
+ (when notes-props
+ (org-remark-highlight-put-props ov notes-props))
+ ;; Save the notes buffer when not loading
+ (unless (eq notes-buf (current-buffer))
+ (with-current-buffer notes-buf (save-buffer)))))) ;;
LINE. save-buffer triggers something that deletes this highilght
+ (deactivate-mark)
+ (org-remark-highlights-housekeep) ;;LINE is a zero width overlay! Need
to escape them.
+ (org-remark-highlights-sort)
+ (setq org-remark-source-setup-done t)
+ ;; Return overlay
+ ov)))
+
+(provide 'org-remark-line)
+;;; org-remark-line.el ends here
diff --git a/org-remark.el b/org-remark.el
index 73594da79f..f7d6699f04 100644
--- a/org-remark.el
+++ b/org-remark.el
@@ -6,7 +6,7 @@
;; URL: https://github.com/nobiot/org-remark
;; Version: 1.1.0
;; Created: 22 December 2020
-;; Last modified: 31 July 2023
+;; Last modified: 01 August 2023
;; Package-Requires: ((emacs "27.1") (org "9.4"))
;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp,
@@ -978,9 +978,11 @@ beginning of source-headline, which should be one level
up."
props (overlay-properties highlight)
id (plist-get props 'org-remark-id)
text (org-with-wide-buffer
- (replace-regexp-in-string
- "\n" " "
- (buffer-substring-no-properties beg end)))
+ (if (string= "line" (overlay-get highlight 'org-remark-type))
+ "Line highlight" ;; for now
+ (replace-regexp-in-string
+ "\n" " "
+ (buffer-substring-no-properties beg end))))
filename (org-remark-source-get-file-name
(org-remark-source-find-file-name))
link (run-hook-with-args-until-success
@@ -1530,6 +1532,7 @@ Case 2. The overlay points to no buffer
;; this, we check if the buffer is write-able and only remove the
;; annotation when it is.
(when (and (overlay-buffer ov)
+ (not (string= "line" (overlay-get ov 'org-remark-type)))
(= (overlay-start ov) (overlay-end ov)))
(when (and (not buffer-read-only)
(not (derived-mode-p 'special-mode)))
@@ -1563,6 +1566,7 @@ extensions."
;; Check that the original text exists AND it is different to the
;; current text
(when (and highlight-text
+ (not (string= "line" (overlay-get ov 'org-remark-type)))
(not (org-remark-string=
highlight-text
(buffer-substring-no-properties
- [elpa] externals/org-remark updated (c33e2b7c77 -> 822e730fc8), ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 6e3254d231 03/75: refactor: highlight headlne text, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 15150c8d40 07/75: feat(line): highlight a whole line, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark a2311005ff 08/75: fix(line): Ensure line hl ovs are always at bol, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 6b4c196f86 12/75: feat: icon for line highlight, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 3a9884e5df 26/75: fix(line): When buffer is first created, window may not be created, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 199702118a 30/75: fix(line): Disable line-mode should disable the margins, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 447fc2beaf 04/75: feat(line): highlight level headline text, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark ded8fddddd 01/75: initial prototype to explore what needs to change,
ELPA Syncer <=
- [elpa] externals/org-remark 0f2bf566ee 10/75: docs(info): source comments, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark f679d00c0a 06/75: refactor(line): loading and renaming the el file, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 2bba54b535 05/75: fix: selecting wrong highlight when opening, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 51c3d91585 11/75: refactor: create macro & menus, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark ae376d860d 09/75: refactor(line): method name change, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 89ee82935c 14/75: fix: window margins do not persist, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 16958accc2 02/75: refactor: org-remark-mark, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark da73102a2d 19/75: fix(line): When source is narrowed line-hl moves the wrong place, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 79ad1baf7e 20/75: refactor(line): no need for text-scale-mode-hook, ELPA Syncer, 2023/10/06
- [elpa] externals/org-remark 0829e27379 39/75: fix(line): redraw instead of reload when window size changes, ELPA Syncer, 2023/10/06