nobiot / org-remark

Highlight & annotate text, EWW, Info, and EPUB
https://nobiot.github.io/org-remark/
GNU General Public License v3.0
425 stars 20 forks source link

Why not removing the full note? #7

Closed magthe closed 2 years ago

magthe commented 3 years ago

The documentation of org-marginalia-remove states that

It will remove the highlight, and remove the properties from the marginalia, but will keep the headline and notes.

What's the reason for this?

I was very surprised when I observed this behaviour. Is there some way of making org-marginalia-remove remove the full note?

nobiot commented 3 years ago

@magthe ,

The reason is simple. I am very conservative about my computer to delete stuff (especially for written work). You could have written extensive marginal notes for an entry. I wanted to make it a very deliberate editing activity to delete the notes -- visit the marginalia file, and manually edit them out.

Having said this.... This could be my idiosyncrasy. I have been asked this question before. I am adding an option to pass C-u (universal argument) to delete the subtree along with the notes you have written.

I would love to add a prompt (yes/no), which you could turn off by customizing, if there is any written note in addition to the properties and link -- I haven't found a way to do so yet. There are a couple of more enhancements I have done to my local -- cannot merge with GitHub repo yet, as I haven't done proper documentation.

I will come back to this hopefully in April/May. I need to be working on a deadline coming from another part of my life.

magthe commented 3 years ago

That's a good reason for doing it that way. I'm looking into org-marginalia for rather short-lived notes, such as code reviews. In those cases I envision that removing the full note is much more common.

Adding C-u sounds like an excellent solution, then I can hopefully simplify my very hacky attempt at doing it:

(defun mt/org-marginalia-remove (point)
  "Remove the note at POINT."
  (interactive "d")
  (when-let* ((id (get-char-property point 'org-marginalia-id))
              (mks (cdr (assoc id org-marginalia-highlights))))
    ;; Remove the highlight text prop and id
    (remove-list-of-text-properties (marker-position (car mks)) (marker-position (cdr mks)) '(org-marginalia-id font-lock-face))
    ;; Remove the element in the variable org-marginalia-highlights
    (setq org-marginalia-highlights (assoc-delete-all id org-marginalia-highlights))
    (org-marginalia-sort-highlights-list)
    ;; Update the marginalia note file accordingly
    (with-current-buffer (find-file-noselect org-marginalia-notes-file-path)
      (org-with-wide-buffer
       (when-let ((id-headline (org-find-property org-marginalia-prop-id id)))
         (goto-char id-headline)
         (org-cut-subtree))))
    t))
nobiot commented 3 years ago

This is what I have currently. Not very different to what you have done:

(defun org-marginalia-remove (point &optional arg)
  "Remove the highlight at POINT.
It will remove the highlight, and remove the properties from the
marginalia, but will keep the headline and notes.

You can pass a universal argument with
\\[universal-argument] (ARG). If this is the case, the command
additionally deletes the entire heading subtree, along with the
notes you have written, for the highlight."
  (interactive "d\nP")
  (when-let* ((id (get-char-property point 'org-marginalia-id))
              (mks (cdr (assoc id org-marginalia-highlights))))
    ;; Remove the highlight text prop and id
    (remove-list-of-text-properties (marker-position (car mks)) (marker-position (cdr mks)) '(org-marginalia-id font-lock-face))
    ;; Remove the element in the variable org-marginalia-highlights
    (setq org-marginalia-highlights (assoc-delete-all id org-marginalia-highlights))
    (org-marginalia-sort-highlights-list)
    ;; Update the marginalia note file accordingly
    (with-current-buffer (find-file-noselect org-marginalia-notes-file-path)
      (org-with-wide-buffer
       (when-let ((id-headline (org-find-property org-marginalia-prop-id id)))
         (goto-char id-headline)
         (org-narrow-to-subtree)
         (org-delete-property org-marginalia-prop-id)
         (org-delete-property org-marginalia-prop-source-beg)
         (org-delete-property org-marginalia-prop-source-end)
         (when arg
           ;; TODO I would love to add the y-n prompt if there is any notes written
           (delete-region (point-min)(point-max))
           (message "Deleted the marginal notes.")))))
    t))
nobiot commented 3 years ago

dev branch is in the repo now, for what it is worth...

magthe commented 3 years ago

The change in https://github.com/nobiot/org-marginalia/commit/2d152c19f8868753212497463fc808d54c5fd77f works beautifully!

I turned my function into a tiny wrapper in order to bind it to a key:

(defun mt/org-marginalia-remove (point)
  "Remove the note at POINT."
  (interactive "d")
  (org-marginalia-remove point t))

This is perfect! Thanks!

nobiot commented 2 years ago

This change has been incorporated in v0.0.6.

README:

org-marginalia-remove

This command removes the highlight at point. It will remove the highlight, and remove the properties from the marginalia, but will keep the headline and notes in tact.

You can pass a universal argument (C-u by default). If this is the case, the command additionally deletes the entire heading subtree, along with the notes you have written, for the highlight.