branch: elpa/annotate commit 39fc4bbda2bb84c038e1be248ddce277d8b7a559 Author: cage <cage-invalid@invalid> Commit: cage <cage-invalid@invalid>
- added an annotation summary window the command 'annotate-show-annotation-summary' popup a window containing a textual description of the annotations found in the annotation file (like ~/.emacs/annotations) with the format: ------- /path/of/an/annotated/file - annotation text - annotation text /another/path/of/an/annotated/file - annotation text ... ------- Each annotation text is a link that, if activated (via a mouse click, for example), opens a buffer showing the annotated file at the position of the annotated text (the underlined one) linked to annotation. --- annotate.el | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/annotate.el b/annotate.el index 276dffd95c..e113a5d3de 100644 --- a/annotate.el +++ b/annotate.el @@ -66,6 +66,8 @@ (define-key annotate-mode-map (kbd "C-c C-a") 'annotate-annotate) +(define-key annotate-mode-map (kbd "C-c C-s") 'annotate-show-annotation-summary) + (define-key annotate-mode-map (kbd "C-c ]") 'annotate-next-annotation) (define-key annotate-mode-map (kbd "C-c [") 'annotate-previous-annotation) @@ -128,6 +130,11 @@ major mode is a member of this list (space separated entries)." :type '(repeat symbol) :group 'annotate) +(defcustom annotate-summary-link-max-width 64 + "Cut the link text in a summary windows to this maximum size (in character)" + :type 'number + :group 'annotate) + (defun annotate-initialize-maybe () "Initialize annotate mode only if buffer's major mode is not in the blacklist (see: 'annotate-blacklist-major-mode'" @@ -730,6 +737,25 @@ file." file." (nth 1 record)) +(defun annotate-filename-from-dump (record) + "Get the filename field from an annotation list loaded from a +file." + (cl-first record)) + +(defun annotate-start-annotation-dump (annotation) + "Get the starting point of an annotation. The arg 'annotation' must be a single +annotation field got from a file dump of all annotated buffers, +essentially what you get from: +(annotate-annotations-from-dump (annotate-load-annotations))). " + (cl-first annotation)) + +(defun annotate-text-annotation-dump (annotation) + "Get the text of an annotation. The arg 'annotation' must be a single +annotation field got from a file dump of all annotated buffers, +essentially what you get from: +(annotate-annotations-from-dump (annotate-load-annotations))). " + (nth 2 annotation)) + (defun annotate-load-annotation-old-format () "Load all annotations from disk in old format." (interactive) @@ -896,5 +922,48 @@ file." (with-temp-file annotate-file (prin1 data (current-buffer)))) +(define-button-type 'annotate-summary-button + 'follow-link t + 'help-echo "Click to show") + +(defun annotate-summary-button-pressed (button) + "Callback called when a sunmmary button is activated" + (let ((buffer (find-file-other-window (button-get button 'file)))) + (with-current-buffer buffer + (goto-char (button-get button 'go-to))))) + +(defun annotate-show-annotation-summary () + "Show a summary of all the annotations in a temp buffer" + (interactive) + (cl-labels ((ellipsize (text) + (if (> (string-width text) + annotate-summary-link-max-width) + (concat (subseq text 0 (- annotate-summary-link-max-width 3)) + "...") + text))) + (with-temp-buffer-window + "*annotations*" nil nil + (with-current-buffer "*annotations*" + (use-local-map nil) + (local-set-key "q" (lambda () + (interactive) + (kill-buffer "*annotations*"))) + (let ((dump (annotate-load-annotation-data))) + (dolist (annotation dump) + (let ((all-annotations (annotate-annotations-from-dump annotation)) + (filename (annotate-filename-from-dump annotation))) + (when (not (null all-annotations)) + (insert (format "%s\n\n" filename)) + (dolist (annotation-field all-annotations) + (let ((button-text (format "%s" + (annotate-text-annotation-dump annotation-field)))) + (insert "- ") + (insert-button (propertize (ellipsize button-text) 'face 'bold) + 'file filename + 'go-to (annotate-start-annotation-dump annotation-field) + 'action 'annotate-summary-button-pressed + 'type 'annotate-summary-button) + (insert "\n\n"))))))))))) + (provide 'annotate) ;;; annotate.el ends here