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.
28 (eval-when-compile (require 'cl))
29 (eval-when-compile (require 'static))
33 (defvar gnus-score-mode-hook nil
34 "*Hook run in score mode buffers.")
36 (defvar gnus-score-menu-hook nil
37 "*Hook run after creating the score mode menu.")
39 (defvar gnus-score-edit-exit-function nil
40 "Function run on exit from the score buffer.")
42 (defvar gnus-score-mode-map nil)
43 (unless gnus-score-mode-map
44 (setq gnus-score-mode-map (make-sparse-keymap))
45 (set-keymap-parent gnus-score-mode-map emacs-lisp-mode-map)
46 (define-key gnus-score-mode-map "\C-c\C-c" 'gnus-score-edit-exit)
47 (define-key gnus-score-mode-map "\C-c\C-d" 'gnus-score-edit-insert-date)
48 (define-key gnus-score-mode-map "\C-c\C-p" 'gnus-score-pretty-print))
50 (defvar score-mode-syntax-table
51 (let ((table (copy-syntax-table lisp-mode-syntax-table)))
52 (modify-syntax-entry ?| "w" table)
54 "Syntax table used in score-mode buffers.")
56 (defvar score-mode-coding-system (static-if (boundp 'MULE)
61 (defun gnus-score-mode ()
62 "Mode for editing Gnus score files.
63 This mode is an extended emacs-lisp mode.
65 \\{gnus-score-mode-map}"
67 (kill-all-local-variables)
68 (use-local-map gnus-score-mode-map)
69 (gnus-score-make-menu-bar)
70 (set-syntax-table score-mode-syntax-table)
71 (setq major-mode 'gnus-score-mode)
72 (setq mode-name "Score")
73 (lisp-mode-variables nil)
74 (make-local-variable 'gnus-score-edit-exit-function)
75 (run-hooks 'emacs-lisp-mode-hook 'gnus-score-mode-hook))
77 (defun gnus-score-make-menu-bar ()
78 (unless (boundp 'gnus-score-menu)
80 gnus-score-menu gnus-score-mode-map ""
82 ["Exit" gnus-score-edit-exit t]
83 ["Insert date" gnus-score-edit-insert-date t]
84 ["Format" gnus-score-pretty-print t]))
85 (run-hooks 'gnus-score-menu-hook)))
87 (defun gnus-score-edit-insert-date ()
88 "Insert date in numerical format."
90 (princ (time-to-days (current-time)) (current-buffer)))
92 (defun gnus-score-pretty-print ()
93 "Format the current score file."
95 (goto-char (point-min))
96 (let ((form (read (current-buffer))))
98 (let ((emacs-lisp-mode-syntax-table score-mode-syntax-table))
99 (pp form (current-buffer))))
100 (goto-char (point-min)))
102 (defun gnus-score-edit-exit ()
103 "Stop editing the score file."
105 (unless (file-exists-p (file-name-directory (buffer-file-name)))
106 (make-directory (file-name-directory (buffer-file-name)) t))
107 (save-buffer-as-coding-system score-mode-coding-system)
108 (bury-buffer (current-buffer))
109 (let ((buf (current-buffer)))
110 (when gnus-score-edit-exit-function
111 (funcall gnus-score-edit-exit-function))
112 (when (eq buf (current-buffer))
113 (switch-to-buffer (other-buffer (current-buffer))))))
115 (provide 'score-mode)
117 ;;; score-mode.el ends here