1 ;;; score-mode.el --- mode for editing Gnus score files
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: news, mail
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
31 (defvar gnus-score-mode-hook nil
32 "*Hook run in score mode buffers.")
34 (defvar gnus-score-menu-hook nil
35 "*Hook run after creating the score mode menu.")
37 (defvar gnus-score-edit-exit-function nil
38 "Function run on exit from the score buffer.")
40 (defvar gnus-score-mode-map nil)
41 (unless gnus-score-mode-map
42 (setq gnus-score-mode-map (copy-keymap emacs-lisp-mode-map))
43 (define-key gnus-score-mode-map "\C-c\C-c" 'gnus-score-edit-exit)
44 (define-key gnus-score-mode-map "\C-c\C-d" 'gnus-score-edit-insert-date)
45 (define-key gnus-score-mode-map "\C-c\C-p" 'gnus-score-pretty-print))
47 (defvar score-mode-syntax-table
48 (let ((table (copy-syntax-table lisp-mode-syntax-table)))
49 (modify-syntax-entry ?| "w" table)
51 "Syntax table used in score-mode buffers.")
53 (defvar score-mode-coding-system 'binary)
56 (defun gnus-score-mode ()
57 "Mode for editing Gnus score files.
58 This mode is an extended emacs-lisp mode.
60 \\{gnus-score-mode-map}"
62 (kill-all-local-variables)
63 (use-local-map gnus-score-mode-map)
64 (gnus-score-make-menu-bar)
65 (set-syntax-table score-mode-syntax-table)
66 (setq major-mode 'gnus-score-mode)
67 (setq mode-name "Score")
68 (lisp-mode-variables nil)
69 (make-local-variable 'gnus-score-edit-exit-function)
70 (run-hooks 'emacs-lisp-mode-hook 'gnus-score-mode-hook))
72 (defun gnus-score-make-menu-bar ()
73 (unless (boundp 'gnus-score-menu)
75 gnus-score-menu gnus-score-mode-map ""
77 ["Exit" gnus-score-edit-exit t]
78 ["Insert date" gnus-score-edit-insert-date t]
79 ["Format" gnus-score-pretty-print t]))
80 (run-hooks 'gnus-score-menu-hook)))
82 (defun gnus-score-edit-insert-date ()
83 "Insert date in numerical format."
85 (princ (time-to-days (current-time)) (current-buffer)))
87 (defun gnus-score-pretty-print ()
88 "Format the current score file."
90 (goto-char (point-min))
91 (let ((form (read (current-buffer))))
93 (let ((emacs-lisp-mode-syntax-table score-mode-syntax-table))
94 (pp form (current-buffer))))
95 (goto-char (point-min)))
97 (defun gnus-score-edit-exit ()
98 "Stop editing the score file."
100 (unless (file-exists-p (file-name-directory (buffer-file-name)))
101 (make-directory (file-name-directory (buffer-file-name)) t))
102 (let ((coding-system-for-write score-mode-coding-system))
104 (bury-buffer (current-buffer))
105 (let ((buf (current-buffer)))
106 (when gnus-score-edit-exit-function
107 (funcall gnus-score-edit-exit-function))
108 (when (eq buf (current-buffer))
109 (switch-to-buffer (other-buffer (current-buffer))))))
111 (provide 'score-mode)
113 ;;; score-mode.el ends here