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

hook for notes file #40

Closed basaran closed 1 year ago

basaran commented 2 years ago

Hello, thank you for org-remark. I just started using it today. Is there a hook we can use for doing things on a marginalia.org after invoking org-remark-open.

For instance, I use auto-fill in my org files, and should like to disable it for marginalia.org. It opens by default on a slim buffer already. What would be the best way to go at this?

I am now using a slightly modified org-remark-open to disable the auto-fill mode.

nobiot commented 2 years ago

Thank you. No no hook yet but happy to add one. Would you mind sharing your slightly modified version?

basaran commented 2 years ago

Hi there, after going at this a few times, this is what I came up with:

(with-eval-after-load 'org-remark
  (defvar org-remark-open-hook nil "Hook for function `org-remark-open'.")

  (defun org-remark-open (point &optional view-only)
    "naha"
    (interactive "d\nP")
    (when-let ((id (get-char-property point 'org-remark-id))
               (ibuf (org-remark-notes-buffer-get-or-create))
               (cbuf (current-buffer)))
      (pop-to-buffer ibuf org-remark-notes-display-buffer-action)
      (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 highlight.  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))
      ;; Avoid error when buffer-action is set to display a new frame
      (when-let ((view-only view-only)
                 (window (get-buffer-window cbuf)))
        (select-window window))
      (run-hooks 'org-remark-open-hook)))

  (add-hook 'org-remark-open-hook
            (lambda ()
              (with-current-buffer (org-remark-notes-get-file-name)
                (visual-fill-column-mode 1)
                (auto-fill-mode 0)))))

I can send a PR for it later if you like.

nobiot commented 2 years ago

Would you mind testing the branch named "hook", please? As noted in the customizing documentation for org-remark-open-hook, the current-buffer should be the note's buffer -- so you don't need to specifically call with-current-buffer -- it is already the note buffer.

Let me know how you go -- or also let me know if you are not familiar with Git to test a branch; we should be able to figure something out for you.

basaran commented 2 years ago

Hello, I will try to get to it today and let you know. I got sucked into some display-buffer-alist drama yesterday.

nobiot commented 1 year ago

Closing with commit e958e3f