[Top][All Lists]

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

edit-list.el v0.1

From: Michael Olson
Subject: edit-list.el v0.1
Date: Sun, 30 Mar 2008 21:53:47 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

So you've just added an incorrect entry to auto-mode-alist and want to
fix it quickly.  `M-x edit-list RET auto-mode-alist RET' to the rescue.
Make your changes and hit either `C-x C-s' or `C-c C-c' when done.  Or
just kill the buffer if you change your mind.

;;; Edit List mode

(defvar edit-list-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "C-c C-c") 'edit-list-done)
    (define-key map (kbd "C-x C-s") 'edit-list-done)


(defvar edit-list-list-name nil
  "Name of list currently being edited.")
(make-variable-buffer-local 'edit-list-list-name)

(define-derived-mode edit-list-mode emacs-lisp-mode "Edit-List"
  "Major mode to edit a single list.

(defun edit-list (list-name)
  "Edit a list called LIST-NAME interactively."
  (interactive "SList to edit: ")
  (unless (and list-name (symbolp list-name))
    (error "Given list name is not a symbol"))
  (let ((list-val (symbol-value list-name)))
    (unless (consp list-val)
      (error "Given symbol does not contain a list"))
    (let ((buffer (generate-new-buffer (format "*Edit-List: %s*" list-name))))
      (with-current-buffer buffer
        (setq edit-list-list-name list-name)
        (let ((print-escape-newlines pp-escape-newlines)
              (print-quoted t))
          (prin1 list-val (current-buffer)))
        (setq buffer-undo-list nil))
      (switch-to-buffer buffer)
      (message "Make changes and hit `C-c C-c' when done"))))

(defun edit-list-done ()
  "Save the given buffer back to the original list.
This finishes the work begun by `edit-list'."
  (unless (and edit-list-list-name (symbolp edit-list-list-name)
               (derived-mode-p 'edit-list-mode))
    (error "This is not an Edit-List buffer"))
  (goto-char (point-min))
  (let ((name edit-list-list-name))
    (set name (read (current-buffer)))
    (kill-buffer (current-buffer))
    (message "Saved changes to list `%s'" name)))

|       Michael Olson  |  FSF Associate Member #652     |
|  |  Hobbies: Lisp, HCoop          |
| Projects: Emacs, Muse, ERC, EMMS, ErBot, DVC, Planner |

Attachment: pgpCPem86ravZ.pgp
Description: PGP signature

reply via email to

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