(Reverting): Add anchor.
[emacs.git] / lisp / gnus / score-mode.el
blobda6c447d1155f7d9e1dd70648aeb65e6b60ed876
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)
12 ;; any later version.
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.
24 ;;; Commentary:
26 ;;; Code:
28 (eval-when-compile (require 'cl))
29 (require 'mm-util) ; for mm-auto-save-coding-system
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 (make-sparse-keymap))
43 (set-keymap-parent gnus-score-mode-map emacs-lisp-mode-map)
44 (define-key gnus-score-mode-map "\C-c\C-c" 'gnus-score-edit-exit)
45 (define-key gnus-score-mode-map "\C-c\C-d" 'gnus-score-edit-insert-date)
46 (define-key gnus-score-mode-map "\C-c\C-p" 'gnus-score-pretty-print))
48 (defvar score-mode-syntax-table
49 (let ((table (copy-syntax-table lisp-mode-syntax-table)))
50 (modify-syntax-entry ?| "w" table)
51 table)
52 "Syntax table used in score-mode buffers.")
54 ;; We need this to cope with non-ASCII scoring.
55 (defvar score-mode-coding-system mm-auto-save-coding-system)
57 ;;;###autoload
58 (defun gnus-score-mode ()
59 "Mode for editing Gnus score files.
60 This mode is an extended emacs-lisp mode.
62 \\{gnus-score-mode-map}"
63 (interactive)
64 (kill-all-local-variables)
65 (use-local-map gnus-score-mode-map)
66 (gnus-score-make-menu-bar)
67 (set-syntax-table score-mode-syntax-table)
68 (setq major-mode 'gnus-score-mode)
69 (setq mode-name "Score")
70 (lisp-mode-variables nil)
71 (make-local-variable 'gnus-score-edit-exit-function)
72 (run-hooks 'emacs-lisp-mode-hook 'gnus-score-mode-hook))
74 (defun gnus-score-make-menu-bar ()
75 (unless (boundp 'gnus-score-menu)
76 (easy-menu-define
77 gnus-score-menu gnus-score-mode-map ""
78 '("Score"
79 ["Exit" gnus-score-edit-exit t]
80 ["Insert date" gnus-score-edit-insert-date t]
81 ["Format" gnus-score-pretty-print t]))
82 (run-hooks 'gnus-score-menu-hook)))
84 (defun gnus-score-edit-insert-date ()
85 "Insert date in numerical format."
86 (interactive)
87 (princ (time-to-days (current-time)) (current-buffer)))
89 (defun gnus-score-pretty-print ()
90 "Format the current score file."
91 (interactive)
92 (goto-char (point-min))
93 (let ((form (read (current-buffer))))
94 (erase-buffer)
95 (let ((emacs-lisp-mode-syntax-table score-mode-syntax-table))
96 (pp form (current-buffer))))
97 (goto-char (point-min)))
99 (defun gnus-score-edit-exit ()
100 "Stop editing the score file."
101 (interactive)
102 (unless (file-exists-p (file-name-directory (buffer-file-name)))
103 (make-directory (file-name-directory (buffer-file-name)) t))
104 (let ((coding-system-for-write score-mode-coding-system))
105 (save-buffer))
106 (bury-buffer (current-buffer))
107 (let ((buf (current-buffer)))
108 (when gnus-score-edit-exit-function
109 (funcall gnus-score-edit-exit-function))
110 (when (eq buf (current-buffer))
111 (switch-to-buffer (other-buffer (current-buffer))))))
113 (provide 'score-mode)
115 ;;; arch-tag: a74a416b-2505-4ad4-bc4e-a418c96b8845
116 ;;; score-mode.el ends here