help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Associated notes with documents


From: Pascal Bourguignon
Subject: Re: Associated notes with documents
Date: Thu, 21 Jul 2005 08:39:00 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

"Chris  Lott" <Chris.Lott@gmail.com> writes:

> I'm trying to figure out an automated way to have a "notes" window
> associated with documents while using emacs. Ideally, the associated
> notes file for a document would open up automatically with the document
> inside a split window of some kind. If there were no notes, then
> entering something in that window and saving it would automatically
> create the notes file, which would open with the document next time.
>
> Is there any code out there that does this kind of thing?

No, but it's so easy and so funny to do it yourself!


(defun FILE-NAMESTRING (pathname)
  "Common-Lisp: returns just the name, type, and version components of pathname.
These functions convert pathname into a namestring. The name represented by 
pathname is
returned as a namestring in an implementation-dependent canonical form.
URL:        http://www.lispworks.com/reference/HyperSpec/Body/f_namest.htm
NOTE:       in current implementation pathname=namestring.
RETURN:     the 'basename' of the pathname.
"
  (if (string-match "\\(^.*/\\([^/][^/]*\\)/*$\\)\\|\\(^\\([^/][^/]*\\)/*$\\)"
                    pathname)
    (let ((res (match-string 2 pathname)))
      (if res res (match-string 4 pathname)))
    pathname))


(defun DIRECTORY-NAMESTRING (pathname)
  "Common-Lisp: returns the directory name portion.
These functions convert pathname into a namestring. The name represented by 
pathname is
returned as a namestring in an implementation-dependent canonical form.
URL:        http://www.lispworks.com/reference/HyperSpec/Body/f_namest.htm
NOTE:       in current implementation pathname=namestring.
RETURN:     the 'basename' of the pathname.
"
  (if (string-match "\\(^.*[^/].*\\)/[^/][^/]*/*$" pathname)
      (match-string 1 pathname)
    (if (= ?/ (aref pathname 0)) "/" ".")))


(defun annotation-file-path (file-path)
  (format "%s/.%s"
    (DIRECTORY-NAMESTRING file-path)
    (FILE-NAMESTRING file-path)))


(defun find-annotated-file (filename &optional wildcards)
  "<<TODO: Please Insert Documentation>>"
  (interactive (find-file-read-args "Find file: " nil))
  (let* ((value (find-file-noselect filename nil nil wildcards))
         (files (if (listp value) value (list value)))
         (notes (mapcar (lambda (file-buffer)
                          (let* ((file-path   (buffer-file-name file-buffer))
                                 (note-path   (annotation-file-path file-path)))
                            (find-file-noselect note-path)))
                        files)))
    (delete-other-windows)
    (switch-to-buffer (first files))
    (split-window-vertically)
    (other-window 1)
    (switch-to-buffer (first notes))
    (other-window 1)))


(global-set-key (kbd "C-x C-f") (function find-annotated-file))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Small brave carnivores
Kill pine cones and mosquitoes
Fear vacuum cleaner


reply via email to

[Prev in Thread] Current Thread [Next in Thread]