unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "PT" <spamfilteraccount@gmail.com>
Subject: Re: Annotation mode
Date: 15 Oct 2005 21:56:35 -0700	[thread overview]
Message-ID: <1129438595.215018.113610@g47g2000cwa.googlegroups.com> (raw)
In-Reply-To: <mailman.11318.1129278531.20277.help-gnu-emacs@gnu.org>

I took a look at the options and decided to implement my own solution,
since it was pretty easy. Here it is if someone is interested:


;;; annotate.el --- simple file annotation system
;;;
;;;
;;; M-x annotate-file pops up a window where the annotation for the
;;; current file can be edited. If the annotation window is left open
;;; it always shows the annotation belonging to the current buffer.
;;;
;;;

;;; Code:

(defvar annotate-storage-file "~/.annotate"
  "File containing the stored annotations.")


(defvar annotate-current-buffer nil
  "The last buffer known to be the current one.")

(defvar annotate-window-configuration nil
  "The window configuration before the annoation buffer was
displayed.")


(defun annotate-file ()
  (interactive)
  (annotate-narrow-to-annotation)

  (setq annotate-window-configuration (current-window-configuration))
  (pop-to-buffer (get-file-buffer annotate-storage-file))

  (local-set-key (kbd "C-c C-c") 'annotate-finish)
  (message "Type C-c C-c to hide the annotation buffer.")

  (setq annotate-current-buffer 'nosuchbuffer)
  (ad-activate 'switch-to-buffer))


(defun annotate-narrow-to-annotation ()
  "Narrow the annotation buffer to the portion belonging to the file
associated
wit the current buffer.
If no annotation exists for the file a new section is created.

If the current buffer has no file associated with it then show a
warning message."
  (let* ((buffer (find-file-noselect annotate-storage-file))
         (file (buffer-file-name))
         (filename (if file
                        (expand-file-name file)
                      "nofile")))

    (with-current-buffer buffer
      (widen)
      (unless (equal filename (expand-file-name annotate-storage-file))
        (goto-char (point-min))
        (if (re-search-forward (concat "^\f " filename) nil t)
            (forward-line)
          (goto-char (point-min))
          (insert "\f " filename "\n\n")
          (forward-line -1))

        (let ((begin (point)))
          (if (re-search-forward "^\f" nil t)
              (progn (forward-line -1)
                     (end-of-line))
            (goto-char (point-max)))
          (narrow-to-region begin (point))
          (goto-char (point-min)))

        ;; prepare warning message if it does not exist yet
        (if (and (not file)
                 (= (point-min) (point-max)))
            (insert "The current buffer has no file associated with it,
"
                    "so it cannot have an annotation."))))))


(defadvice switch-to-buffer (after annotate-handle-buffer-change)
  (annotate-update-annotation-display))


(defun annotate-update-annotation-display ()
  "Synchronize the displayed annotation to the current buffer if the
annotation
window is visible. Otherwise cancel current buffer monitoring."
  (if (get-buffer-window (get-file-buffer annotate-storage-file))
      (unless (equal (current-buffer) annotate-current-buffer)
        (setq annotate-current-buffer (current-buffer))
        (annotate-narrow-to-annotation))

    (ad-deactivate 'switch-to-buffer)))


(defun annotate-finish ()
  "Hide the annotation buffer and restore previous window
configuration."
  (interactive)
  (set-window-configuration annotate-window-configuration)
  (with-current-buffer (get-file-buffer annotate-storage-file)
    (save-buffer)))


(provide 'annotate)
;;; annotate.el ends here

  parent reply	other threads:[~2005-10-16  4:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-14  6:39 Annotation mode PT
2005-10-14  8:09 ` Joe Corneli
     [not found] ` <mailman.11318.1129278531.20277.help-gnu-emacs@gnu.org>
2005-10-16  4:56   ` PT [this message]
2005-10-17 13:51     ` Joe Corneli
2005-10-17 14:40     ` Enila Nero
2005-10-18  6:32       ` PT
     [not found]     ` <mailman.11621.1129557527.20277.help-gnu-emacs@gnu.org>
2005-10-18  6:15       ` PT

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1129438595.215018.113610@g47g2000cwa.googlegroups.com \
    --to=spamfilteraccount@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).