(set-language-environment): Do the real work here.
[emacs.git] / lisp / score-mode.el
blob8505a93185b66c29ffbcd056f70f77251578552f
1 ;;; score-mode.el --- mode for editing Gnus score files
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
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 (require 'easymenu)
29 (require 'timezone)
30 (eval-when-compile (require 'cl))
32 (defvar gnus-score-mode-hook nil
33 "*Hook run in score mode buffers.")
35 (defvar gnus-score-menu-hook nil
36 "*Hook run after creating the score mode menu.")
38 (defvar gnus-score-edit-exit-function nil
39 "Function run on exit from the score buffer.")
41 (defvar gnus-score-mode-map nil)
42 (unless gnus-score-mode-map
43 (setq gnus-score-mode-map (copy-keymap 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 ;;;###autoload
49 (defun gnus-score-mode ()
50 "Mode for editing Gnus score files.
51 This mode is an extended emacs-lisp mode.
53 \\{gnus-score-mode-map}"
54 (interactive)
55 (kill-all-local-variables)
56 (use-local-map gnus-score-mode-map)
57 (when menu-bar-mode
58 (gnus-score-make-menu-bar))
59 (set-syntax-table emacs-lisp-mode-syntax-table)
60 (setq major-mode 'gnus-score-mode)
61 (setq mode-name "Score")
62 (lisp-mode-variables nil)
63 (make-local-variable 'gnus-score-edit-exit-function)
64 (run-hooks 'emacs-lisp-mode-hook 'gnus-score-mode-hook))
66 (defun gnus-score-make-menu-bar ()
67 (unless (boundp 'gnus-score-menu)
68 (easy-menu-define
69 gnus-score-menu gnus-score-mode-map ""
70 '("Score"
71 ["Exit" gnus-score-edit-exit t]
72 ["Insert date" gnus-score-edit-insert-date t]
73 ["Format" gnus-score-pretty-print t]))
74 (run-hooks 'gnus-score-menu-hook)))
76 (defun gnus-score-edit-insert-date ()
77 "Insert date in numerical format."
78 (interactive)
79 (princ (gnus-score-day-number (current-time)) (current-buffer)))
81 (defun gnus-score-pretty-print ()
82 "Format the current score file."
83 (interactive)
84 (goto-char (point-min))
85 (let ((form (read (current-buffer))))
86 (erase-buffer)
87 (pp form (current-buffer)))
88 (goto-char (point-min)))
90 (defun gnus-score-edit-exit ()
91 "Stop editing the score file."
92 (interactive)
93 (unless (file-exists-p (file-name-directory (buffer-file-name)))
94 (make-directory (file-name-directory (buffer-file-name)) t))
95 (save-buffer)
96 (bury-buffer (current-buffer))
97 (let ((buf (current-buffer)))
98 (when gnus-score-edit-exit-function
99 (funcall gnus-score-edit-exit-function))
100 (when (eq buf (current-buffer))
101 (switch-to-buffer (other-buffer (current-buffer))))))
103 (defun gnus-score-day-number (time)
104 (let ((dat (decode-time time)))
105 (timezone-absolute-from-gregorian
106 (nth 4 dat) (nth 3 dat) (nth 5 dat))))
108 (provide 'score-mode)
110 ;;; score-mode.el ends here