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

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

index-cards.el v2


From: Joe Corneli
Subject: index-cards.el v2
Date: Fri, 10 Nov 2006 13:07:02 -0500 (EST)

;;; index-cards.el -- write ersatz index cards with emacs

;; Copyright (C) 2006 Joseph Corneli <address@hidden>
;; Notice: Copyright transfered to public domain wherever applicable.

;; Time-stamp: <2006-11-10 12:05:51 jcorneli>

;;; Commentary:

;; (Version 1.)  Quick hacks using a minibuffer-only frame which make
;; it look and feel sort of like you're writing large index cards on
;; the computer.  Edit and save a new numbered index card each time!

;; (Version 2.) Bugfix.

;;; Code:

(define-derived-mode index-card-mode text-mode "IC"
  "Type up an \"index card\"."
  (set-fill-column 84)
  (auto-fill-mode)
  (auto-save-mode 0)
  ;; I set things up so that the window did not scroll down to follow
  ;; point, but merely let the point move across the open space.
  (set (make-local-variable 'scroll-margin) 0)
  (message nil))

(defvar index-card-directory "~/pma/" "Home for index cards and related info.")

;; You can't switch buffers in the minibuffer frame, so you must chunk in
;; the text from elsewhere.
(defun make-card ()
  (interactive)
  ;; I don't know how to `read' information directly from files
  (let ((card-name (with-temp-buffer 
                     (insert-file-contents (concat index-card-directory
                                                   "card-counter"))
                     (concat "card-"
                             (int-to-string 
                              (read (get-buffer (current-buffer))))
                             ".txt"))))
    (find-file-noselect (concat index-card-directory card-name))
    (cond
     ((condition-case nil
          (not (and (save-excursion (set-buffer (get-buffer " *Minibuf-0*"))
                                    (select-frame-by-name "card"))))
        (error nil)))
     ((make-frame
       '((name . "card")
         (minibuffer . only)))))
    (delete-region (point-min) (point-max))
    (insert-buffer-substring (get-buffer card-name))
    (kill-buffer card-name)
    (goto-char (point-min))
    (index-card-mode)))

;; Right now there no method for temporarily saving the card except to
;; let it sit there: you must finish it directly and then go on to the
;; next one.  (Well, as you see in the above function, if you manually
;; reduce the number kept in the card-counter file, you can edit
;; earlier cards.  This isn't a feature I use daily.)

(defun finish-card ()
  (interactive)
  (let ((content (buffer-string))
        (number (progn (select-frame (previous-frame))
                       (current-buffer)
                       (let ((retval
                              (with-temp-buffer
                                (find-file (concat
                                            index-card-directory 
"card-counter"))
                                (let ((num (read (get-buffer 
(current-buffer)))))
                                  (delete-region (point-min) (1- (point-max)))
                                  (insert (int-to-string (1+ num)))
                                  (save-buffer)
                                  (kill-buffer nil)
                                  num))))
                         (select-frame-by-name "card")
                         retval))))
    (with-temp-file (concat index-card-directory
                            "card-" (int-to-string 
                                     number)
                            ".txt")
      (insert content))
    (delete-region (point-min) (point-max))
    (message (concat "Card " (int-to-string number) 
                     " saved at " (current-time-string) ".")))
  (raise-frame (previous-frame)))

(define-key index-card-mode-map (kbd "C-x z") 'finish-card)

;; It is irritating to have the position of the screen readjust due to
;; navigation and other editing commands.  This turns off some of the
;; annoyance.

(defun my-beginning-of-buffer ()
  (interactive)
  (goto-char (point-min)))

(defun my-end-of-buffer ()
  (interactive)
  (goto-char (point-max)))

(define-key index-card-mode-map [(meta <)] 'my-beginning-of-buffer)
(define-key index-card-mode-map [(meta >)] 'my-end-of-buffer)

;;; index-cards.el ends here





reply via email to

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