annotate lisp/gnus/score-mode.el @ 98:0d2f883870bc r20-1b1

Import from CVS: tag r20-1b1
author cvs
date Mon, 13 Aug 2007 09:13:56 +0200
parents 131b0175ea99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1 ;;; score-mode.el --- mode for editing Gnus score files
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
3
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
5 ;; Keywords: news, mail
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
6
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
8
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
12 ;; any later version.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
13
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
18
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
23
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
24 ;;; Commentary:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
25
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
26 ;;; Code:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
27
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
28 (require 'easymenu)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
29 (require 'timezone)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
30 (eval-when-compile (require 'cl))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
31
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
32 (defvar gnus-score-mode-hook nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
33 "*Hook run in score mode buffers.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
34
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
35 (defvar gnus-score-menu-hook nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
36 "*Hook run after creating the score mode menu.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
37
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
38 (defvar gnus-score-edit-exit-function nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
39 "Function run on exit from the score buffer.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
40
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
41 (defvar gnus-score-mode-map nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
42 (unless gnus-score-mode-map
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
43 (setq gnus-score-mode-map (copy-keymap emacs-lisp-mode-map))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
44 (define-key gnus-score-mode-map "\C-c\C-c" 'gnus-score-edit-exit)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
45 (define-key gnus-score-mode-map "\C-c\C-d" 'gnus-score-edit-insert-date)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
46 (define-key gnus-score-mode-map "\C-c\C-p" 'gnus-score-pretty-print))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
47
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
48 ;;;###autoload
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
49 (defun gnus-score-mode ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
50 "Mode for editing Gnus score files.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
51 This mode is an extended emacs-lisp mode.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
52
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
53 \\{gnus-score-mode-map}"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
54 (interactive)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
55 (kill-all-local-variables)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
56 (use-local-map gnus-score-mode-map)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
57 (gnus-score-make-menu-bar)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
58 (set-syntax-table emacs-lisp-mode-syntax-table)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
59 (setq major-mode 'gnus-score-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
60 (setq mode-name "Score")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
61 (lisp-mode-variables nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
62 (make-local-variable 'gnus-score-edit-exit-function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
63 (run-hooks 'emacs-lisp-mode-hook 'gnus-score-mode-hook))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
64
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
65 (defun gnus-score-make-menu-bar ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
66 (unless (boundp 'gnus-score-menu)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
67 (easy-menu-define
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
68 gnus-score-menu gnus-score-mode-map ""
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
69 '("Score"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
70 ["Exit" gnus-score-edit-exit t]
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
71 ["Insert date" gnus-score-edit-insert-date t]
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
72 ["Format" gnus-score-pretty-print t]))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
73 (run-hooks 'gnus-score-menu-hook)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
74
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
75 (defun gnus-score-edit-insert-date ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
76 "Insert date in numerical format."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
77 (interactive)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
78 (princ (gnus-score-day-number (current-time)) (current-buffer)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
79
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
80 (defun gnus-score-pretty-print ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
81 "Format the current score file."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
82 (interactive)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
83 (goto-char (point-min))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
84 (let ((form (read (current-buffer))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
85 (erase-buffer)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
86 (pp form (current-buffer)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
87 (goto-char (point-min)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
88
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
89 (defun gnus-score-edit-exit ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
90 "Stop editing the score file."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
91 (interactive)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
92 (unless (file-exists-p (file-name-directory (buffer-file-name)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
93 (make-directory (file-name-directory (buffer-file-name)) t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
94 (save-buffer)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
95 (bury-buffer (current-buffer))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
96 (let ((buf (current-buffer)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
97 (when gnus-score-edit-exit-function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
98 (funcall gnus-score-edit-exit-function))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
99 (when (eq buf (current-buffer))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
100 (switch-to-buffer (other-buffer (current-buffer))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
101
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
102 (defun gnus-score-day-number (time)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
103 (let ((dat (decode-time time)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
104 (timezone-absolute-from-gregorian
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
105 (nth 4 dat) (nth 3 dat) (nth 5 dat))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
106
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
107 (provide 'score-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
108
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
109 ;;; score-mode.el ends here