emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org-remark a1ff9033c1 170/173: add: org-remark-delete


From: ELPA Syncer
Subject: [elpa] externals/org-remark a1ff9033c1 170/173: add: org-remark-delete
Date: Fri, 28 Jan 2022 16:58:13 -0500 (EST)

branch: externals/org-remark
commit a1ff9033c11d9299d11768f5c22e9c45066b8c42
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>

    add: org-remark-delete
    
    Delete the highlight at POINT and marginal notes for it.
    
    This function will prompt for confirmation if there is any notes present in 
the
    marginal notes buffer.  When the marginal notes buffer is not displayed in 
the
    current frame, it will be temporarily displayed together with the prompt 
for the
    user to see the notes.
    
    If there is no notes, this function will not prompt for confirmation and 
will
    remove the highlight and deletes the entry in the marginal notes buffer.
    
    This command is identical with passing a universal argument to
    `org-remark-remove'. "
---
 NEWS          |  8 ++++--
 README.org    |  7 -----
 org-remark.el | 91 ++++++++++++++++++++++++++++++++++++-----------------------
 3 files changed, 62 insertions(+), 44 deletions(-)

diff --git a/NEWS b/NEWS
index c285823547..80da7863fd 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+Version 0.2.0
+  - add: org-remark-delete
+
+Version 0.1.0
 * Features & additions
 
   - docs: comprehensive user manual (online - Info to be added on ELPA release)
@@ -12,7 +16,7 @@
   - add: browse-next/prev: move and display next/prev marginal notes at the 
same
          time
 
-  - add: visit/open to display side-window by default (user option)
+  - add: view/open to display side-window by default (user option)
 
   - add: org-remark-link property in marginal notes file with ::line-number
          search option
@@ -33,7 +37,7 @@
 
   - chg: define org-remark-mark explicitly for autoload cookie
 
-  - chg: `org-remark-visit' and `org-remark-open'. Visit will stay in the
+  - chg: `org-remark-view' and `org-remark-open'. View will stay in the
           current main note; open will move the cursor to the marginal notes
           buffer for further editing.
 
diff --git a/README.org b/README.org
index f55602bcd5..bbf31ab7d4 100644
--- a/README.org
+++ b/README.org
@@ -105,12 +105,5 @@ This work is licensed under a GPLv3 license. For a full 
copy of the license, ref
 This section is created by Org-remark for the source file. It serves as an 
example to illustrate what Org-remark can do.
 
 ** defmacro org-remark-create
-:PROPERTIES:
-:org-remark-beg: 4001
-:org-remark-end: 4027
-:org-remark-id: c759f435
-:org-remark-label: nil
-:org-remark-link: [[file:~/src/org-remark/org-remark.el::120]]
-:END:
 
 This macro was inspired by 
[[https://github.com/jkitchin/ov-highlight][Ov-highlight]].  It's by John 
Kitchin (author of Org-ref). Great UX for markers with hydra. Saves the marker 
info and comments directly within the Org file as Base64 encoded string. It 
uses overlays with using ~ov~ package.
diff --git a/org-remark.el b/org-remark.el
index 229e843a8a..313eb85cc9 100644
--- a/org-remark.el
+++ b/org-remark.el
@@ -4,7 +4,7 @@
 
 ;; Author: Noboru Ota <me@nobiot.com>
 ;; URL: https://github.com/nobiot/org-remark
-;; Version: 0.1.0
+;; Version: 0.2.0
 ;; Created: 22 December 2020
 ;; Last modified: 26 January 2022
 ;; Package-Requires: ((emacs "27.1") (org "9.4"))
@@ -407,12 +407,14 @@ notes file by tracking it."
   (when-let ((id (get-char-property point 'org-remark-id))
              (ibuf (org-remark-notes-buffer-get-or-create))
              (cbuf (current-buffer)))
-    (set-buffer ibuf)(widen)
-    (when-let (p (org-find-property org-remark-prop-id id))
-      (goto-char p)(org-narrow-to-subtree)(org-end-of-meta-data t))
     (display-buffer ibuf org-remark-notes-display-buffer-action)
-    ;; For some reason, to change the display, the window needs to be selected
     (select-window (get-buffer-window ibuf))
+    (widen)
+    (when-let (p (org-find-property org-remark-prop-id id))
+      ;; Somehow recenter is needed when a highlight is deleted and move to a
+      ;; previous.  Otherwise, the cursor is too low to show the entire entry.
+      ;; It looks like there is no entry.
+      (goto-char p)(org-narrow-to-subtree)(org-end-of-meta-data t)(recenter))
     (when view-only (select-window (get-buffer-window cbuf)))))
 
 (defun org-remark-view (point)
@@ -533,6 +535,24 @@ and removing overlays are not part of the undo tree."
     (org-remark-highlights-sort)
     t))
 
+(defun org-remark-delete (point)
+  "Delete the highlight at POINT and marginal notes for it.
+
+This function will prompt for confirmation if there is any notes
+present in the marginal notes buffer.  When the marginal notes
+buffer is not displayed in the current frame, it will be
+temporarily displayed together with the prompt for the user to
+see the notes.
+
+If there is no notes, this function will not prompt for
+confirmation and will remove the highlight and deletes the entry
+in the marginal notes buffer.
+
+This command is identical with passing a universal argument to
+`org-remark-remove'. "
+  (interactive "d")
+  (org-remark-remove point :delete))
+
 
 ;;;; Internal Functions
 
@@ -786,37 +806,38 @@ the headline intact.  You can pass DELETE and delete the 
all
 notes of the entry.
 
 Return t if an entry is removed or deleted."
-  (let ((note-buf (find-file-noselect org-remark-notes-file-path)))
-    (with-current-buffer note-buf
-      (let* ((ibuf (org-remark-notes-buffer-get-or-create))
-             (ibuf-window (get-buffer-window ibuf)))
-        (org-with-wide-buffer
-         (when-let ((id-headline (org-find-property org-remark-prop-id id)))
-           (goto-char id-headline)
-           (org-narrow-to-subtree)
-           (dolist (prop (org-entry-properties))
-             (when (string-prefix-p "org-remark-" (downcase (car prop)))
-               (org-delete-property (car prop))))
-           (when delete
-             (org-end-of-meta-data t)
-             (when-let (ok-to-delete?
-                        (if (looking-at ".")
-                            ;; If there is a content, display and prompt for
-                            ;; confirmation
-                            (progn
-                              ;; This does not display the location correctly
-                              (display-buffer ibuf
-                                              
org-remark-notes-display-buffer-action)
-                              (y-or-n-p "Highlight removed but notes exist. \
+  (let* ((ibuf (org-remark-notes-buffer-get-or-create))
+         (ibuf-window (get-buffer-window ibuf)))
+    (with-current-buffer ibuf
+      (org-with-wide-buffer
+       (when-let ((id-headline (org-find-property org-remark-prop-id id)))
+         (goto-char id-headline)
+         (org-narrow-to-subtree)
+         (dolist (prop (org-entry-properties))
+           (when (string-prefix-p "org-remark-" (downcase (car prop)))
+             (org-delete-property (car prop))))
+         (when delete
+           ;; CATEGORY prop won't be deleted. Move to line after props
+           (org-end-of-meta-data t)
+           (when-let (ok-to-delete?
+                      (if (looking-at ".")
+                          ;; If there is a content, display and prompt for
+                          ;; confirmation
+                          (progn
+                            ;; This does not display the location correctly
+                            (display-buffer ibuf
+                                            
org-remark-notes-display-buffer-action)
+                            (y-or-n-p "Highlight removed but notes exist. \
 Do you really want to delete the notes?"))
-                          ;; If there is no content, it's OK
-                          t))
-               (delete-region (point-min)(point-max))
-               (message "Deleted the marginal notes entry")
-               (unless ibuf-window (quit-window nil
-                                                (get-buffer-window ibuf)))))))
-        (when (buffer-modified-p) (save-buffer))
-        t))))
+                        ;; If there is no content, it's OK
+                        t))
+             (delete-region (point-min)(point-max))
+             (message "Deleted the marginal notes entry")))))
+             ;; Quit the marginal notes indirect buffer if it was not there
+             ;; before the delete -- go back to the original state.
+             ;;(unless ibuf-window (quit-window nil (get-buffer-window 
ibuf)))))))
+      (when (buffer-modified-p) (save-buffer)))
+    t))
 
 (defun org-remark-notes-buffer-get-or-create ()
   "Return marginal notes buffer.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]