1 ;;; gnus-scomo.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)
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.
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
))
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}"
55 (kill-all-local-variables)
56 (use-local-map gnus-score-mode-map
)
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
)
69 gnus-score-menu gnus-score-mode-map
""
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."
79 (princ (gnus-score-day-number (current-time)) (current-buffer)))
81 (defun gnus-score-pretty-print ()
82 "Format the current score file."
84 (goto-char (point-min))
85 (let ((form (read (current-buffer))))
87 (pp form
(current-buffer)))
88 (goto-char (point-min)))
90 (defun gnus-score-edit-exit ()
91 "Stop editing the score file."
93 (unless (file-exists-p (file-name-directory (buffer-file-name)))
94 (make-directory (file-name-directory (buffer-file-name)) t
))
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 'gnus-scomo
)
110 ;;; gnus-scomo.el ends here