all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Pascal Bourguignon <pjb@informatimago.com>
Subject: Re: Associated notes with documents
Date: Thu, 21 Jul 2005 08:39:00 +0200	[thread overview]
Message-ID: <87y8808xyz.fsf@thalassa.informatimago.com> (raw)
In-Reply-To: 1121914017.718653.310620@z14g2000cwz.googlegroups.com

"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	other threads:[~2005-07-21  6:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-21  2:46 Associated notes with documents Chris  Lott
2005-07-21  6:39 ` Pascal Bourguignon [this message]
2005-07-24 16:25   ` Chris  Lott
2005-07-24 16:30     ` Adrian Aichner
2005-07-21  6:59 ` Joe Corneli

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

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

  git send-email \
    --in-reply-to=87y8808xyz.fsf@thalassa.informatimago.com \
    --to=pjb@informatimago.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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.