bastibe/annotate.el

[feature request] enable annotating Info manual

Closed this issue · 4 comments

Dear the maintainers of the package of annotate.el:

Thanks for writing this package, I find it useful when reading
computer programs. It makes my ideas seamlessly intergrated with
the sources very well.

My initial idea was to use this package to annotate the Info
manual. I found that it is very enjoyable to read the Elisp
manual inside the Info mode, so I thougth it would be better if I
could annotate my thoughts directly into the Info manual.

I tweaked some of the functions before Sept. 24. I was able to
achieve the function. Please see the following GIFs. I did not
report to you because I thought my code was not robust.

  1. Able to write notes in Info mode:
    a
  2. Able to write notes in the sub-nodes:
    b
  3. After reopen Emacs, it can reload all the notes in the Info manual:
    c

There are many commits after Sept. 24 and after that my tweaks
were not compatable with your code.

I was wondering that if someone could make a decent pull request
to this package.

Followings are my tweaks, and I hope it can help someone
interested in making it.

Thanks for your effort. Really appreciate it.

(add-to-list 'load-path "~/.emacs.d/annotate.el")
(require 'annotate)
(setq annotate-file (expand-file-name "~/Dropbox/myNote/annotations"))


;; for info file

;;;###autoload
(define-minor-mode annotate-mode
  "Toggle Annotate mode."
  :init-value nil
  :lighter " Ann"
  :keymap (make-sparse-keymap)
  :group 'annotate
  :after-hook (if annotate-mode
                  (progn (annotate-initialize) (split-window-below) (delete-other-windows))
                (annotate-shutdown)))

(defun tweak-annotate-load-annotations ()
  "Load all annotations from disk."
  (interactive)
  (let ((annotations (cdr (assoc-string
                           (substring-no-properties (or Info-current-file ""))
                           (annotate-load-annotation-data))))
        (modified-p (buffer-modified-p)))
    ;; remove empty annotations created by earlier bug:
    (setq annotations (cl-remove-if (lambda (ann) (eq (nth 2 ann) nil))
                                    annotations))
    (message "annotate is %s" annotations)
    (when (and (eq nil annotations) annotate-use-messages)
      (message "No annotations found."))
    (when (not (eq nil annotations))
      (save-excursion
        (dolist (annotation annotations)
          (let ((start (nth 0 annotation))
                (end (nth 1 annotation))
                (text (nth 2 annotation)))
            (message "hi")
            (annotate-create-annotation start end text)))))
    (set-buffer-modified-p modified-p)
    (font-lock-fontify-buffer)
    (if annotate-use-messages
        (message "Annotations loaded."))))

(defun annotate-initialize ()
  "Load annotations and set up save and display hooks."
  (tweak-annotate-load-annotations)
  (add-hook 'after-save-hook 'annotate-save-annotations t t)
  (add-hook 'window-configuration-change-hook 'font-lock-fontify-buffer t t)
  (font-lock-add-keywords
   nil '((annotate--font-lock-matcher (2 (annotate--annotation-builder))
                                      (1 (annotate--change-guard))))))

(defun tweak-annotate-save-annotations ()
  "Save all annotations to disk."
  (interactive)
  (let ((file-annotations (annotate-describe-annotations))
        (all-annotations (annotate-load-annotation-data))
        (filename Info-current-file))
    (if (assoc-string filename all-annotations)
        (setcdr (assoc-string filename all-annotations)
                file-annotations)
      (setq all-annotations
            (push (cons filename file-annotations)
                  all-annotations)))
    ;; remove duplicate entries (a user reported seeing them)
    (dolist (entry all-annotations)
      (delete-dups entry))
    ;; skip files with no annotations
    (annotate-dump-annotation-data (cl-remove-if
                                    (lambda (entry)
                                      (eq nil (cdr entry)))
                                    all-annotations))
    (if annotate-use-messages
        (message "Annotations saved."))))
cage2 commented
cage2 commented

Hello to everyone!
@bastibe i have some code that try to deal with this feature, my idea is: i could push this modification on my fork and, with kind collaboration from @randomwangran , we can check if my code meets his request or not. Then, if it does, i can issue pull request. Are you ok if i work on this request? Is this way to work good?

Bye!
C.

Absolutely! Or just open the pull request and we can collaborate on it in the pull request right away. I'm fine with using a pull request as a discussion platform.

cage2 commented

Hi!
I think we (Bastibe and me) added the feature you requested, therefore i am closing this. If you do believe there are still things to do please feel free to reopen this issue!

Bye!
C.