Mercurial > emacs
annotate lisp/gnus/gnus-salt.el @ 19852:f3de43ba64e5
Recognize ARC cpu.
author | Doug Evans <dje@gnu.org> |
---|---|
date | Tue, 09 Sep 1997 22:23:48 +0000 |
parents | 6f6cf9184e93 |
children | 5f1ab3dd344d |
rev | line source |
---|---|
17493 | 1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus |
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
5 | |
6 ;; This file is part of GNU Emacs. | |
7 | |
8 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
10 ;; the Free Software Foundation; either version 2, or (at your option) | |
11 ;; any later version. | |
12 | |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 ;; Boston, MA 02111-1307, USA. | |
22 | |
23 ;;; Commentary: | |
24 | |
25 ;;; Code: | |
26 | |
19521
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
27 (eval-when-compile (require 'cl)) |
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
28 |
17493 | 29 (require 'gnus) |
30 (require 'gnus-sum) | |
31 | |
32 ;;; | |
33 ;;; gnus-pick-mode | |
34 ;;; | |
35 | |
36 (defvar gnus-pick-mode nil | |
37 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.") | |
38 | |
39 (defvar gnus-pick-display-summary nil | |
40 "*Display summary while reading.") | |
41 | |
42 (defvar gnus-pick-mode-hook nil | |
43 "Hook run in summary pick mode buffers.") | |
44 | |
45 (defvar gnus-mark-unpicked-articles-as-read nil | |
46 "*If non-nil, mark all unpicked articles as read.") | |
47 | |
48 (defvar gnus-pick-elegant-flow t | |
49 "If non-nil, gnus-pick-start-reading will run gnus-summary-next-group when no articles have been picked.") | |
50 | |
51 (defvar gnus-summary-pick-line-format | |
52 "%-5P %U\%R\%z\%I\%(%[%4L: %-20,20n%]%) %s\n" | |
53 "*The format specification of the lines in pick buffers. | |
54 It accepts the same format specs that `gnus-summary-line-format' does.") | |
55 | |
56 ;;; Internal variables. | |
57 | |
58 (defvar gnus-pick-mode-map nil) | |
59 | |
60 (unless gnus-pick-mode-map | |
61 (setq gnus-pick-mode-map (make-sparse-keymap)) | |
62 | |
63 (gnus-define-keys | |
64 gnus-pick-mode-map | |
65 "t" gnus-uu-mark-thread | |
66 "T" gnus-uu-unmark-thread | |
67 " " gnus-pick-next-page | |
68 "u" gnus-summary-unmark-as-processable | |
69 "U" gnus-summary-unmark-all-processable | |
70 "v" gnus-uu-mark-over | |
71 "r" gnus-uu-mark-region | |
72 "R" gnus-uu-unmark-region | |
73 "e" gnus-uu-mark-by-regexp | |
74 "E" gnus-uu-mark-by-regexp | |
75 "b" gnus-uu-mark-buffer | |
76 "B" gnus-uu-unmark-buffer | |
77 "." gnus-pick-article | |
78 gnus-down-mouse-2 gnus-pick-mouse-pick-region | |
79 ;;gnus-mouse-2 gnus-pick-mouse-pick | |
80 "X" gnus-pick-start-reading | |
81 "\r" gnus-pick-start-reading)) | |
82 | |
83 (defun gnus-pick-make-menu-bar () | |
84 (unless (boundp 'gnus-pick-menu) | |
85 (easy-menu-define | |
86 gnus-pick-menu gnus-pick-mode-map "" | |
87 '("Pick" | |
88 ("Pick" | |
89 ["Article" gnus-summary-mark-as-processable t] | |
90 ["Thread" gnus-uu-mark-thread t] | |
91 ["Region" gnus-uu-mark-region t] | |
92 ["Regexp" gnus-uu-mark-regexp t] | |
93 ["Buffer" gnus-uu-mark-buffer t]) | |
94 ("Unpick" | |
95 ["Article" gnus-summary-unmark-as-processable t] | |
96 ["Thread" gnus-uu-unmark-thread t] | |
97 ["Region" gnus-uu-unmark-region t] | |
98 ["Regexp" gnus-uu-unmark-regexp t] | |
99 ["Buffer" gnus-uu-unmark-buffer t]) | |
100 ["Start reading" gnus-pick-start-reading t] | |
101 ["Switch pick mode off" gnus-pick-mode gnus-pick-mode])))) | |
102 | |
103 (defun gnus-pick-mode (&optional arg) | |
104 "Minor mode for providing a pick-and-read interface in Gnus summary buffers. | |
105 | |
106 \\{gnus-pick-mode-map}" | |
107 (interactive "P") | |
108 (when (eq major-mode 'gnus-summary-mode) | |
109 (if (not (set (make-local-variable 'gnus-pick-mode) | |
110 (if (null arg) (not gnus-pick-mode) | |
111 (> (prefix-numeric-value arg) 0)))) | |
112 (remove-hook 'gnus-message-setup-hook 'gnus-pick-setup-message) | |
113 ;; Make sure that we don't select any articles upon group entry. | |
114 (set (make-local-variable 'gnus-auto-select-first) nil) | |
115 ;; Change line format. | |
116 (setq gnus-summary-line-format gnus-summary-pick-line-format) | |
117 (setq gnus-summary-line-format-spec nil) | |
118 (gnus-update-format-specifications nil 'summary) | |
119 (gnus-update-summary-mark-positions) | |
120 (add-hook 'gnus-message-setup-hook 'gnus-pick-setup-message) | |
121 (set (make-local-variable 'gnus-summary-goto-unread) 'never) | |
122 ;; Set up the menu. | |
123 (when (gnus-visual-p 'pick-menu 'menu) | |
124 (gnus-pick-make-menu-bar)) | |
125 (unless (assq 'gnus-pick-mode minor-mode-alist) | |
126 (push '(gnus-pick-mode " Pick") minor-mode-alist)) | |
127 (unless (assq 'gnus-pick-mode minor-mode-map-alist) | |
128 (push (cons 'gnus-pick-mode gnus-pick-mode-map) | |
129 minor-mode-map-alist)) | |
130 (run-hooks 'gnus-pick-mode-hook)))) | |
131 | |
132 (defun gnus-pick-setup-message () | |
133 "Make Message do the right thing on exit." | |
134 (when (and (gnus-buffer-live-p gnus-summary-buffer) | |
135 (save-excursion | |
136 (set-buffer gnus-summary-buffer) | |
137 gnus-pick-mode)) | |
138 (message-add-action | |
139 '(gnus-configure-windows 'pick t) 'send 'exit 'postpone 'kill))) | |
140 | |
141 (defvar gnus-pick-line-number 1) | |
142 (defun gnus-pick-line-number () | |
143 "Return the current line number." | |
144 (if (bobp) | |
145 (setq gnus-pick-line-number 1) | |
146 (incf gnus-pick-line-number))) | |
147 | |
148 (defun gnus-pick-start-reading (&optional catch-up) | |
149 "Start reading the picked articles. | |
150 If given a prefix, mark all unpicked articles as read." | |
151 (interactive "P") | |
152 (if gnus-newsgroup-processable | |
153 (progn | |
154 (gnus-summary-limit-to-articles nil) | |
155 (when (or catch-up gnus-mark-unpicked-articles-as-read) | |
156 (gnus-summary-limit-mark-excluded-as-read)) | |
157 (gnus-summary-first-article) | |
158 (gnus-configure-windows | |
159 (if gnus-pick-display-summary 'article 'pick) t)) | |
160 (if gnus-pick-elegant-flow | |
161 (progn | |
162 (when (or catch-up gnus-mark-unpicked-articles-as-read) | |
163 (gnus-summary-limit-mark-excluded-as-read)) | |
164 (if (gnus-group-quit-config gnus-newsgroup-name) | |
165 (gnus-summary-exit) | |
166 (gnus-summary-next-group))) | |
167 (error "No articles have been picked")))) | |
168 | |
169 (defun gnus-pick-article (&optional arg) | |
170 "Pick the article on the current line. | |
171 If ARG, pick the article on that line instead." | |
172 (interactive "P") | |
173 (when arg | |
174 (let (pos) | |
175 (save-excursion | |
176 (goto-char (point-min)) | |
177 (when (zerop (forward-line (1- (prefix-numeric-value arg)))) | |
178 (setq pos (point)))) | |
179 (if (not pos) | |
180 (gnus-error 2 "No such line: %s" arg) | |
181 (goto-char pos)))) | |
182 (gnus-summary-mark-as-processable 1)) | |
183 | |
184 (defun gnus-pick-mouse-pick (e) | |
185 (interactive "e") | |
186 (mouse-set-point e) | |
187 (save-excursion | |
188 (gnus-summary-mark-as-processable 1))) | |
189 | |
190 (defun gnus-pick-mouse-pick-region (start-event) | |
191 "Pick articles that the mouse is dragged over. | |
192 This must be bound to a button-down mouse event." | |
193 (interactive "e") | |
194 (mouse-minibuffer-check start-event) | |
195 (let* ((echo-keystrokes 0) | |
196 (start-posn (event-start start-event)) | |
197 (start-point (posn-point start-posn)) | |
198 (start-line (1+ (count-lines 1 start-point))) | |
199 (start-window (posn-window start-posn)) | |
200 (start-frame (window-frame start-window)) | |
201 (bounds (window-edges start-window)) | |
202 (top (nth 1 bounds)) | |
203 (bottom (if (window-minibuffer-p start-window) | |
204 (nth 3 bounds) | |
205 ;; Don't count the mode line. | |
206 (1- (nth 3 bounds)))) | |
207 (click-count (1- (event-click-count start-event)))) | |
208 (setq mouse-selection-click-count click-count) | |
209 (setq mouse-selection-click-count-buffer (current-buffer)) | |
210 (mouse-set-point start-event) | |
211 ;; In case the down click is in the middle of some intangible text, | |
212 ;; use the end of that text, and put it in START-POINT. | |
213 (when (< (point) start-point) | |
214 (goto-char start-point)) | |
215 (gnus-pick-article) | |
216 (setq start-point (point)) | |
217 ;; end-of-range is used only in the single-click case. | |
218 ;; It is the place where the drag has reached so far | |
219 ;; (but not outside the window where the drag started). | |
220 (let (event end end-point last-end-point (end-of-range (point))) | |
221 (track-mouse | |
222 (while (progn | |
223 (setq event (read-event)) | |
224 (or (mouse-movement-p event) | |
225 (eq (car-safe event) 'switch-frame))) | |
226 (if (eq (car-safe event) 'switch-frame) | |
227 nil | |
228 (setq end (event-end event) | |
229 end-point (posn-point end)) | |
230 (when end-point | |
231 (setq last-end-point end-point)) | |
232 | |
233 (cond | |
234 ;; Are we moving within the original window? | |
235 ((and (eq (posn-window end) start-window) | |
236 (integer-or-marker-p end-point)) | |
237 ;; Go to START-POINT first, so that when we move to END-POINT, | |
238 ;; if it's in the middle of intangible text, | |
239 ;; point jumps in the direction away from START-POINT. | |
240 (goto-char start-point) | |
241 (goto-char end-point) | |
242 (gnus-pick-article) | |
243 ;; In case the user moved his mouse really fast, pick | |
244 ;; articles on the line between this one and the last one. | |
245 (let* ((this-line (1+ (count-lines 1 end-point))) | |
246 (min-line (min this-line start-line)) | |
247 (max-line (max this-line start-line))) | |
248 (while (< min-line max-line) | |
249 (goto-line min-line) | |
250 (gnus-pick-article) | |
251 (setq min-line (1+ min-line))) | |
252 (setq start-line this-line)) | |
253 (when (zerop (% click-count 3)) | |
254 (setq end-of-range (point)))) | |
255 (t | |
256 (let ((mouse-row (cdr (cdr (mouse-position))))) | |
257 (cond | |
258 ((null mouse-row)) | |
259 ((< mouse-row top) | |
260 (mouse-scroll-subr start-window (- mouse-row top))) | |
261 ((>= mouse-row bottom) | |
262 (mouse-scroll-subr start-window | |
263 (1+ (- mouse-row bottom))))))))))) | |
264 (when (consp event) | |
265 (let ((fun (key-binding (vector (car event))))) | |
266 ;; Run the binding of the terminating up-event, if possible. | |
267 ;; In the case of a multiple click, it gives the wrong results, | |
268 ;; because it would fail to set up a region. | |
269 (when nil | |
270 ;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun)) | |
271 ;; In this case, we can just let the up-event execute normally. | |
272 (let ((end (event-end event))) | |
273 ;; Set the position in the event before we replay it, | |
274 ;; because otherwise it may have a position in the wrong | |
275 ;; buffer. | |
276 (setcar (cdr end) end-of-range) | |
277 ;; Delete the overlay before calling the function, | |
278 ;; because delete-overlay increases buffer-modified-tick. | |
279 (push event unread-command-events)))))))) | |
280 | |
281 (defun gnus-pick-next-page () | |
282 "Go to the next page. If at the end of the buffer, start reading articles." | |
283 (interactive) | |
284 (let ((scroll-in-place nil)) | |
285 (condition-case nil | |
286 (scroll-up) | |
287 (end-of-buffer (gnus-pick-start-reading))))) | |
288 | |
289 ;;; | |
290 ;;; gnus-binary-mode | |
291 ;;; | |
292 | |
293 (defvar gnus-binary-mode nil | |
294 "Minor mode for providing a binary group interface in Gnus summary buffers.") | |
295 | |
296 (defvar gnus-binary-mode-hook nil | |
297 "Hook run in summary binary mode buffers.") | |
298 | |
299 (defvar gnus-binary-mode-map nil) | |
300 | |
301 (unless gnus-binary-mode-map | |
302 (setq gnus-binary-mode-map (make-sparse-keymap)) | |
303 | |
304 (gnus-define-keys | |
305 gnus-binary-mode-map | |
306 "g" gnus-binary-show-article)) | |
307 | |
308 (defun gnus-binary-make-menu-bar () | |
309 (unless (boundp 'gnus-binary-menu) | |
310 (easy-menu-define | |
311 gnus-binary-menu gnus-binary-mode-map "" | |
312 '("Pick" | |
313 ["Switch binary mode off" gnus-binary-mode t])))) | |
314 | |
315 (defun gnus-binary-mode (&optional arg) | |
316 "Minor mode for providing a binary group interface in Gnus summary buffers." | |
317 (interactive "P") | |
318 (when (eq major-mode 'gnus-summary-mode) | |
319 (make-local-variable 'gnus-binary-mode) | |
320 (setq gnus-binary-mode | |
321 (if (null arg) (not gnus-binary-mode) | |
322 (> (prefix-numeric-value arg) 0))) | |
323 (when gnus-binary-mode | |
324 ;; Make sure that we don't select any articles upon group entry. | |
325 (make-local-variable 'gnus-auto-select-first) | |
326 (setq gnus-auto-select-first nil) | |
327 (make-local-variable 'gnus-summary-display-article-function) | |
328 (setq gnus-summary-display-article-function 'gnus-binary-display-article) | |
329 ;; Set up the menu. | |
330 (when (gnus-visual-p 'binary-menu 'menu) | |
331 (gnus-binary-make-menu-bar)) | |
332 (unless (assq 'gnus-binary-mode minor-mode-alist) | |
333 (push '(gnus-binary-mode " Binary") minor-mode-alist)) | |
334 (unless (assq 'gnus-binary-mode minor-mode-map-alist) | |
335 (push (cons 'gnus-binary-mode gnus-binary-mode-map) | |
336 minor-mode-map-alist)) | |
337 (run-hooks 'gnus-binary-mode-hook)))) | |
338 | |
339 (defun gnus-binary-display-article (article &optional all-header) | |
340 "Run ARTICLE through the binary decode functions." | |
341 (when (gnus-summary-goto-subject article) | |
342 (let ((gnus-view-pseudos 'automatic)) | |
343 (gnus-uu-decode-uu)))) | |
344 | |
345 (defun gnus-binary-show-article (&optional arg) | |
346 "Bypass the binary functions and show the article." | |
347 (interactive "P") | |
348 (let (gnus-summary-display-article-function) | |
349 (gnus-summary-show-article arg))) | |
350 | |
351 ;;; | |
352 ;;; gnus-tree-mode | |
353 ;;; | |
354 | |
355 (defvar gnus-tree-line-format "%(%[%3,3n%]%)" | |
356 "Format of tree elements.") | |
357 | |
358 (defvar gnus-tree-minimize-window t | |
359 "If non-nil, minimize the tree buffer window. | |
360 If a number, never let the tree buffer grow taller than that number of | |
361 lines.") | |
362 | |
363 (defvar gnus-selected-tree-face 'modeline | |
364 "*Face used for highlighting selected articles in the thread tree.") | |
365 | |
366 (defvar gnus-tree-brackets '((?\[ . ?\]) (?\( . ?\)) | |
367 (?\{ . ?\}) (?< . ?>)) | |
368 "Brackets used in tree nodes.") | |
369 | |
370 (defvar gnus-tree-parent-child-edges '(?- ?\\ ?|) | |
371 "Characters used to connect parents with children.") | |
372 | |
373 (defvar gnus-tree-mode-line-format "Gnus: %%b %S %Z" | |
374 "*The format specification for the tree mode line.") | |
375 | |
376 (defvar gnus-generate-tree-function 'gnus-generate-vertical-tree | |
377 "*Function for generating a thread tree. | |
378 Two predefined functions are available: | |
379 `gnus-generate-horizontal-tree' and `gnus-generate-vertical-tree'.") | |
380 | |
381 (defvar gnus-tree-mode-hook nil | |
382 "*Hook run in tree mode buffers.") | |
383 | |
384 ;;; Internal variables. | |
385 | |
386 (defvar gnus-tree-line-format-alist | |
387 `((?n gnus-tmp-name ?s) | |
388 (?f gnus-tmp-from ?s) | |
389 (?N gnus-tmp-number ?d) | |
390 (?\[ gnus-tmp-open-bracket ?c) | |
391 (?\] gnus-tmp-close-bracket ?c) | |
392 (?s gnus-tmp-subject ?s))) | |
393 | |
394 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist) | |
395 | |
396 (defvar gnus-tree-mode-line-format-spec nil) | |
397 (defvar gnus-tree-line-format-spec nil) | |
398 | |
399 (defvar gnus-tree-node-length nil) | |
400 (defvar gnus-selected-tree-overlay nil) | |
401 | |
402 (defvar gnus-tree-displayed-thread nil) | |
403 | |
404 (defvar gnus-tree-mode-map nil) | |
405 (put 'gnus-tree-mode 'mode-class 'special) | |
406 | |
407 (unless gnus-tree-mode-map | |
408 (setq gnus-tree-mode-map (make-keymap)) | |
409 (suppress-keymap gnus-tree-mode-map) | |
410 (gnus-define-keys | |
411 gnus-tree-mode-map | |
412 "\r" gnus-tree-select-article | |
413 gnus-mouse-2 gnus-tree-pick-article | |
414 "\C-?" gnus-tree-read-summary-keys | |
415 | |
416 "\C-c\C-i" gnus-info-find-node) | |
417 | |
418 (substitute-key-definition | |
419 'undefined 'gnus-tree-read-summary-keys gnus-tree-mode-map)) | |
420 | |
421 (defun gnus-tree-make-menu-bar () | |
422 (unless (boundp 'gnus-tree-menu) | |
423 (easy-menu-define | |
424 gnus-tree-menu gnus-tree-mode-map "" | |
425 '("Tree" | |
426 ["Select article" gnus-tree-select-article t])))) | |
427 | |
428 (defun gnus-tree-mode () | |
429 "Major mode for displaying thread trees." | |
430 (interactive) | |
431 (setq gnus-tree-mode-line-format-spec | |
432 (gnus-parse-format gnus-tree-mode-line-format | |
433 gnus-summary-mode-line-format-alist)) | |
434 (setq gnus-tree-line-format-spec | |
435 (gnus-parse-format gnus-tree-line-format | |
436 gnus-tree-line-format-alist t)) | |
437 (when (gnus-visual-p 'tree-menu 'menu) | |
438 (gnus-tree-make-menu-bar)) | |
439 (kill-all-local-variables) | |
440 (gnus-simplify-mode-line) | |
441 (setq mode-name "Tree") | |
442 (setq major-mode 'gnus-tree-mode) | |
443 (use-local-map gnus-tree-mode-map) | |
444 (buffer-disable-undo (current-buffer)) | |
445 (setq buffer-read-only t) | |
446 (setq truncate-lines t) | |
447 (save-excursion | |
448 (gnus-set-work-buffer) | |
449 (gnus-tree-node-insert (make-mail-header "") nil) | |
450 (setq gnus-tree-node-length (1- (point)))) | |
451 (run-hooks 'gnus-tree-mode-hook)) | |
452 | |
453 (defun gnus-tree-read-summary-keys (&optional arg) | |
454 "Read a summary buffer key sequence and execute it." | |
455 (interactive "P") | |
456 (let ((buf (current-buffer)) | |
457 win) | |
458 (gnus-article-read-summary-keys arg nil t) | |
459 (when (setq win (get-buffer-window buf)) | |
460 (select-window win) | |
461 (when gnus-selected-tree-overlay | |
462 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1))) | |
463 (gnus-tree-minimize)))) | |
464 | |
465 (defun gnus-tree-select-article (article) | |
466 "Select the article under point, if any." | |
467 (interactive (list (gnus-tree-article-number))) | |
468 (let ((buf (current-buffer))) | |
469 (when article | |
470 (save-excursion | |
471 (set-buffer gnus-summary-buffer) | |
472 (gnus-summary-goto-article article)) | |
473 (select-window (get-buffer-window buf))))) | |
474 | |
475 (defun gnus-tree-pick-article (e) | |
476 "Select the article under the mouse pointer." | |
477 (interactive "e") | |
478 (mouse-set-point e) | |
479 (gnus-tree-select-article (gnus-tree-article-number))) | |
480 | |
481 (defun gnus-tree-article-number () | |
482 (get-text-property (point) 'gnus-number)) | |
483 | |
484 (defun gnus-tree-article-region (article) | |
485 "Return a cons with BEG and END of the article region." | |
486 (let ((pos (text-property-any (point-min) (point-max) 'gnus-number article))) | |
487 (when pos | |
488 (cons pos (next-single-property-change pos 'gnus-number))))) | |
489 | |
490 (defun gnus-tree-goto-article (article) | |
491 (let ((pos (text-property-any (point-min) (point-max) 'gnus-number article))) | |
492 (when pos | |
493 (goto-char pos)))) | |
494 | |
495 (defun gnus-tree-recenter () | |
496 "Center point in the tree window." | |
497 (let ((selected (selected-window)) | |
498 (tree-window (get-buffer-window gnus-tree-buffer t))) | |
499 (when tree-window | |
500 (select-window tree-window) | |
501 (when gnus-selected-tree-overlay | |
502 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1))) | |
503 (let* ((top (cond ((< (window-height) 4) 0) | |
504 ((< (window-height) 7) 1) | |
505 (t 2))) | |
506 (height (1- (window-height))) | |
507 (bottom (save-excursion (goto-char (point-max)) | |
508 (forward-line (- height)) | |
509 (point)))) | |
510 ;; Set the window start to either `bottom', which is the biggest | |
511 ;; possible valid number, or the second line from the top, | |
512 ;; whichever is the least. | |
513 (set-window-start | |
514 tree-window (min bottom (save-excursion | |
515 (forward-line (- top)) (point))))) | |
516 (select-window selected)))) | |
517 | |
518 (defun gnus-get-tree-buffer () | |
519 "Return the tree buffer properly initialized." | |
520 (save-excursion | |
521 (set-buffer (get-buffer-create gnus-tree-buffer)) | |
522 (unless (eq major-mode 'gnus-tree-mode) | |
523 (gnus-add-current-to-buffer-list) | |
524 (gnus-tree-mode)) | |
525 (current-buffer))) | |
526 | |
527 (defun gnus-tree-minimize () | |
528 (when (and gnus-tree-minimize-window | |
529 (not (one-window-p))) | |
530 (let ((windows 0) | |
531 tot-win-height) | |
532 (walk-windows (lambda (window) (incf windows))) | |
533 (setq tot-win-height | |
534 (- (frame-height) | |
535 (* window-min-height (1- windows)) | |
536 2)) | |
537 (let* ((window-min-height 2) | |
538 (height (count-lines (point-min) (point-max))) | |
539 (min (max (1- window-min-height) height)) | |
540 (tot (if (numberp gnus-tree-minimize-window) | |
541 (min gnus-tree-minimize-window min) | |
542 min)) | |
543 (win (get-buffer-window (current-buffer))) | |
544 (wh (and win (1- (window-height win))))) | |
545 (setq tot (min tot tot-win-height)) | |
546 (when (and win | |
547 (not (eq tot wh))) | |
548 (let ((selected (selected-window))) | |
549 (when (ignore-errors (select-window win)) | |
550 (enlarge-window (- tot wh)) | |
551 (select-window selected)))))))) | |
552 | |
553 ;;; Generating the tree. | |
554 | |
555 (defun gnus-tree-node-insert (header sparse &optional adopted) | |
556 (let* ((dummy (stringp header)) | |
557 (header (if (vectorp header) header | |
558 (progn | |
559 (setq header (make-mail-header "*****")) | |
560 (mail-header-set-number header 0) | |
561 (mail-header-set-lines header 0) | |
562 (mail-header-set-chars header 0) | |
563 header))) | |
564 (gnus-tmp-from (mail-header-from header)) | |
565 (gnus-tmp-subject (mail-header-subject header)) | |
566 (gnus-tmp-number (mail-header-number header)) | |
567 (gnus-tmp-name | |
568 (cond | |
569 ((string-match "(.+)" gnus-tmp-from) | |
570 (substring gnus-tmp-from | |
571 (1+ (match-beginning 0)) (1- (match-end 0)))) | |
572 ((string-match "<[^>]+> *$" gnus-tmp-from) | |
573 (let ((beg (match-beginning 0))) | |
574 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from) | |
575 (substring gnus-tmp-from (1+ (match-beginning 0)) | |
576 (1- (match-end 0)))) | |
577 (substring gnus-tmp-from 0 beg)))) | |
578 ((memq gnus-tmp-number sparse) | |
579 "***") | |
580 (t gnus-tmp-from))) | |
581 (gnus-tmp-open-bracket | |
582 (cond ((memq gnus-tmp-number sparse) | |
583 (caadr gnus-tree-brackets)) | |
584 (dummy (caaddr gnus-tree-brackets)) | |
585 (adopted (car (nth 3 gnus-tree-brackets))) | |
586 (t (caar gnus-tree-brackets)))) | |
587 (gnus-tmp-close-bracket | |
588 (cond ((memq gnus-tmp-number sparse) | |
589 (cdadr gnus-tree-brackets)) | |
590 (adopted (cdr (nth 3 gnus-tree-brackets))) | |
591 (dummy | |
592 (cdaddr gnus-tree-brackets)) | |
593 (t (cdar gnus-tree-brackets)))) | |
594 (buffer-read-only nil) | |
595 beg end) | |
596 (gnus-add-text-properties | |
597 (setq beg (point)) | |
598 (setq end (progn (eval gnus-tree-line-format-spec) (point))) | |
599 (list 'gnus-number gnus-tmp-number)) | |
600 (when (or t (gnus-visual-p 'tree-highlight 'highlight)) | |
601 (gnus-tree-highlight-node gnus-tmp-number beg end)))) | |
602 | |
603 (defun gnus-tree-highlight-node (article beg end) | |
604 "Highlight current line according to `gnus-summary-highlight'." | |
605 (let ((list gnus-summary-highlight) | |
606 face) | |
607 (save-excursion | |
608 (set-buffer gnus-summary-buffer) | |
609 (let* ((score (or (cdr (assq article gnus-newsgroup-scored)) | |
610 gnus-summary-default-score 0)) | |
611 (default gnus-summary-default-score) | |
612 (mark (or (gnus-summary-article-mark article) gnus-unread-mark))) | |
613 ;; Eval the cars of the lists until we find a match. | |
614 (while (and list | |
615 (not (eval (caar list)))) | |
616 (setq list (cdr list))))) | |
617 (unless (eq (setq face (cdar list)) (get-text-property beg 'face)) | |
618 (gnus-put-text-property | |
619 beg end 'face | |
620 (if (boundp face) (symbol-value face) face))))) | |
621 | |
622 (defun gnus-tree-indent (level) | |
623 (insert (make-string (1- (* (1+ gnus-tree-node-length) level)) ? ))) | |
624 | |
625 (defvar gnus-tmp-limit) | |
626 (defvar gnus-tmp-sparse) | |
627 (defvar gnus-tmp-indent) | |
628 | |
629 (defun gnus-generate-tree (thread) | |
630 "Generate a thread tree for THREAD." | |
631 (save-excursion | |
632 (set-buffer (gnus-get-tree-buffer)) | |
633 (let ((buffer-read-only nil) | |
634 (gnus-tmp-indent 0)) | |
635 (erase-buffer) | |
636 (funcall gnus-generate-tree-function thread 0) | |
637 (gnus-set-mode-line 'tree) | |
638 (goto-char (point-min)) | |
639 (gnus-tree-minimize) | |
640 (gnus-tree-recenter) | |
641 (let ((selected (selected-window))) | |
642 (when (get-buffer-window (set-buffer gnus-tree-buffer) t) | |
643 (select-window (get-buffer-window (set-buffer gnus-tree-buffer) t)) | |
644 (gnus-horizontal-recenter) | |
645 (select-window selected)))))) | |
646 | |
647 (defun gnus-generate-horizontal-tree (thread level &optional dummyp adopted) | |
648 "Generate a horizontal tree." | |
649 (let* ((dummy (stringp (car thread))) | |
650 (do (or dummy | |
651 (memq (mail-header-number (car thread)) gnus-tmp-limit))) | |
652 col beg) | |
653 (if (not do) | |
654 ;; We don't want this article. | |
655 (setq thread (cdr thread)) | |
656 (if (not (bolp)) | |
657 ;; Not the first article on the line, so we insert a "-". | |
658 (insert (car gnus-tree-parent-child-edges)) | |
659 ;; If the level isn't zero, then we insert some indentation. | |
660 (unless (zerop level) | |
661 (gnus-tree-indent level) | |
662 (insert (cadr gnus-tree-parent-child-edges)) | |
663 (setq col (- (setq beg (point)) (gnus-point-at-bol) 1)) | |
664 ;; Draw "|" lines upwards. | |
665 (while (progn | |
666 (forward-line -1) | |
667 (forward-char col) | |
668 (= (following-char) ? )) | |
669 (delete-char 1) | |
670 (insert (caddr gnus-tree-parent-child-edges))) | |
671 (goto-char beg))) | |
672 (setq dummyp nil) | |
673 ;; Insert the article node. | |
674 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted)) | |
675 (if (null thread) | |
676 ;; End of the thread, so we go to the next line. | |
677 (unless (bolp) | |
678 (insert "\n")) | |
679 ;; Recurse downwards in all children of this article. | |
680 (while thread | |
681 (gnus-generate-horizontal-tree | |
682 (pop thread) (if do (1+ level) level) | |
683 (or dummyp dummy) dummy))))) | |
684 | |
685 (defsubst gnus-tree-indent-vertical () | |
686 (let ((len (- (* (1+ gnus-tree-node-length) gnus-tmp-indent) | |
687 (- (point) (gnus-point-at-bol))))) | |
688 (when (> len 0) | |
689 (insert (make-string len ? ))))) | |
690 | |
691 (defsubst gnus-tree-forward-line (n) | |
692 (while (>= (decf n) 0) | |
693 (unless (zerop (forward-line 1)) | |
694 (end-of-line) | |
695 (insert "\n"))) | |
696 (end-of-line)) | |
697 | |
698 (defun gnus-generate-vertical-tree (thread level &optional dummyp adopted) | |
699 "Generate a vertical tree." | |
700 (let* ((dummy (stringp (car thread))) | |
701 (do (or dummy | |
702 (and (car thread) | |
703 (memq (mail-header-number (car thread)) | |
704 gnus-tmp-limit)))) | |
705 beg) | |
706 (if (not do) | |
707 ;; We don't want this article. | |
708 (setq thread (cdr thread)) | |
709 (if (not (save-excursion (beginning-of-line) (bobp))) | |
710 ;; Not the first article on the line, so we insert a "-". | |
711 (progn | |
712 (gnus-tree-indent-vertical) | |
713 (insert (make-string (/ gnus-tree-node-length 2) ? )) | |
714 (insert (caddr gnus-tree-parent-child-edges)) | |
715 (gnus-tree-forward-line 1)) | |
716 ;; If the level isn't zero, then we insert some indentation. | |
717 (unless (zerop gnus-tmp-indent) | |
718 (gnus-tree-forward-line (1- (* 2 level))) | |
719 (gnus-tree-indent-vertical) | |
720 (delete-char -1) | |
721 (insert (cadr gnus-tree-parent-child-edges)) | |
722 (setq beg (point)) | |
723 ;; Draw "-" lines leftwards. | |
724 (while (progn | |
725 (unless (bolp) | |
726 (forward-char -2)) | |
727 (= (following-char) ? )) | |
728 (delete-char 1) | |
729 (insert (car gnus-tree-parent-child-edges))) | |
730 (goto-char beg) | |
731 (gnus-tree-forward-line 1))) | |
732 (setq dummyp nil) | |
733 ;; Insert the article node. | |
734 (gnus-tree-indent-vertical) | |
735 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted) | |
736 (gnus-tree-forward-line 1)) | |
737 (if (null thread) | |
738 ;; End of the thread, so we go to the next line. | |
739 (progn | |
740 (goto-char (point-min)) | |
741 (end-of-line) | |
742 (incf gnus-tmp-indent)) | |
743 ;; Recurse downwards in all children of this article. | |
744 (while thread | |
745 (gnus-generate-vertical-tree | |
746 (pop thread) (if do (1+ level) level) | |
747 (or dummyp dummy) dummy))))) | |
748 | |
749 ;;; Interface functions. | |
750 | |
751 (defun gnus-possibly-generate-tree (article &optional force) | |
752 "Generate the thread tree for ARTICLE if it isn't displayed already." | |
753 (when (save-excursion | |
754 (set-buffer gnus-summary-buffer) | |
755 (and gnus-use-trees | |
756 gnus-show-threads | |
757 (vectorp (gnus-summary-article-header article)))) | |
758 (save-excursion | |
759 (let ((top (save-excursion | |
760 (set-buffer gnus-summary-buffer) | |
761 (gnus-cut-thread | |
762 (gnus-remove-thread | |
763 (mail-header-id | |
764 (gnus-summary-article-header article)) | |
765 t)))) | |
766 (gnus-tmp-limit gnus-newsgroup-limit) | |
767 (gnus-tmp-sparse gnus-newsgroup-sparse)) | |
768 (when (or force | |
769 (not (eq top gnus-tree-displayed-thread))) | |
770 (gnus-generate-tree top) | |
771 (setq gnus-tree-displayed-thread top)))))) | |
772 | |
773 (defun gnus-tree-open (group) | |
774 (gnus-get-tree-buffer)) | |
775 | |
776 (defun gnus-tree-close (group) | |
777 ;(gnus-kill-buffer gnus-tree-buffer) | |
778 ) | |
779 | |
780 (defun gnus-highlight-selected-tree (article) | |
781 "Highlight the selected article in the tree." | |
782 (let ((buf (current-buffer)) | |
783 region) | |
784 (set-buffer gnus-tree-buffer) | |
785 (when (setq region (gnus-tree-article-region article)) | |
786 (when (or (not gnus-selected-tree-overlay) | |
787 (gnus-extent-detached-p gnus-selected-tree-overlay)) | |
788 ;; Create a new overlay. | |
789 (gnus-overlay-put | |
790 (setq gnus-selected-tree-overlay (gnus-make-overlay 1 2)) | |
791 'face gnus-selected-tree-face)) | |
792 ;; Move the overlay to the article. | |
793 (gnus-move-overlay | |
794 gnus-selected-tree-overlay (goto-char (car region)) (cdr region)) | |
795 (gnus-tree-minimize) | |
796 (gnus-tree-recenter) | |
797 (let ((selected (selected-window))) | |
798 (when (get-buffer-window (set-buffer gnus-tree-buffer) t) | |
799 (select-window (get-buffer-window (set-buffer gnus-tree-buffer) t)) | |
800 (gnus-horizontal-recenter) | |
801 (select-window selected)))) | |
802 ;; If we remove this save-excursion, it updates the wrong mode lines?!? | |
803 (save-excursion | |
804 (set-buffer gnus-tree-buffer) | |
805 (gnus-set-mode-line 'tree)) | |
806 (set-buffer buf))) | |
807 | |
808 (defun gnus-tree-highlight-article (article face) | |
809 (save-excursion | |
810 (set-buffer (gnus-get-tree-buffer)) | |
811 (let (region) | |
812 (when (setq region (gnus-tree-article-region article)) | |
813 (gnus-put-text-property (car region) (cdr region) 'face face) | |
814 (set-window-point | |
815 (get-buffer-window (current-buffer) t) (cdr region)))))) | |
816 | |
817 ;;; | |
818 ;;; gnus-carpal | |
819 ;;; | |
820 | |
821 (defvar gnus-carpal-group-buffer-buttons | |
822 '(("next" . gnus-group-next-unread-group) | |
823 ("prev" . gnus-group-prev-unread-group) | |
824 ("read" . gnus-group-read-group) | |
825 ("select" . gnus-group-select-group) | |
826 ("catch-up" . gnus-group-catchup-current) | |
827 ("new-news" . gnus-group-get-new-news-this-group) | |
828 ("toggle-sub" . gnus-group-unsubscribe-current-group) | |
829 ("subscribe" . gnus-group-unsubscribe-group) | |
830 ("kill" . gnus-group-kill-group) | |
831 ("yank" . gnus-group-yank-group) | |
832 ("describe" . gnus-group-describe-group) | |
833 "list" | |
834 ("subscribed" . gnus-group-list-groups) | |
835 ("all" . gnus-group-list-all-groups) | |
836 ("killed" . gnus-group-list-killed) | |
837 ("zombies" . gnus-group-list-zombies) | |
838 ("matching" . gnus-group-list-matching) | |
839 ("post" . gnus-group-post-news) | |
840 ("mail" . gnus-group-mail) | |
841 ("rescan" . gnus-group-get-new-news) | |
842 ("browse-foreign" . gnus-group-browse-foreign) | |
843 ("exit" . gnus-group-exit))) | |
844 | |
845 (defvar gnus-carpal-summary-buffer-buttons | |
846 '("mark" | |
847 ("read" . gnus-summary-mark-as-read-forward) | |
848 ("tick" . gnus-summary-tick-article-forward) | |
849 ("clear" . gnus-summary-clear-mark-forward) | |
850 ("expirable" . gnus-summary-mark-as-expirable) | |
851 "move" | |
852 ("scroll" . gnus-summary-next-page) | |
853 ("next-unread" . gnus-summary-next-unread-article) | |
854 ("prev-unread" . gnus-summary-prev-unread-article) | |
855 ("first" . gnus-summary-first-unread-article) | |
856 ("best" . gnus-summary-best-unread-article) | |
857 "article" | |
858 ("headers" . gnus-summary-toggle-header) | |
859 ("uudecode" . gnus-uu-decode-uu) | |
860 ("enter-digest" . gnus-summary-enter-digest-group) | |
861 ("fetch-parent" . gnus-summary-refer-parent-article) | |
862 "mail" | |
863 ("move" . gnus-summary-move-article) | |
864 ("copy" . gnus-summary-copy-article) | |
865 ("respool" . gnus-summary-respool-article) | |
866 "threads" | |
867 ("lower" . gnus-summary-lower-thread) | |
868 ("kill" . gnus-summary-kill-thread) | |
869 "post" | |
870 ("post" . gnus-summary-post-news) | |
871 ("mail" . gnus-summary-mail) | |
872 ("followup" . gnus-summary-followup-with-original) | |
873 ("reply" . gnus-summary-reply-with-original) | |
874 ("cancel" . gnus-summary-cancel-article) | |
875 "misc" | |
876 ("exit" . gnus-summary-exit) | |
877 ("fed-up" . gnus-summary-catchup-and-goto-next-group))) | |
878 | |
879 (defvar gnus-carpal-server-buffer-buttons | |
880 '(("add" . gnus-server-add-server) | |
881 ("browse" . gnus-server-browse-server) | |
882 ("list" . gnus-server-list-servers) | |
883 ("kill" . gnus-server-kill-server) | |
884 ("yank" . gnus-server-yank-server) | |
885 ("copy" . gnus-server-copy-server) | |
886 ("exit" . gnus-server-exit))) | |
887 | |
888 (defvar gnus-carpal-browse-buffer-buttons | |
889 '(("subscribe" . gnus-browse-unsubscribe-current-group) | |
890 ("exit" . gnus-browse-exit))) | |
891 | |
892 (defvar gnus-carpal-group-buffer "*Carpal Group*") | |
893 (defvar gnus-carpal-summary-buffer "*Carpal Summary*") | |
894 (defvar gnus-carpal-server-buffer "*Carpal Server*") | |
895 (defvar gnus-carpal-browse-buffer "*Carpal Browse*") | |
896 | |
897 (defvar gnus-carpal-attached-buffer nil) | |
898 | |
899 (defvar gnus-carpal-mode-hook nil | |
900 "*Hook run in carpal mode buffers.") | |
901 | |
902 (defvar gnus-carpal-button-face 'bold | |
903 "*Face used on carpal buttons.") | |
904 | |
905 (defvar gnus-carpal-header-face 'bold-italic | |
906 "*Face used on carpal buffer headers.") | |
907 | |
908 (defvar gnus-carpal-mode-map nil) | |
909 (put 'gnus-carpal-mode 'mode-class 'special) | |
910 | |
911 (if gnus-carpal-mode-map | |
912 nil | |
913 (setq gnus-carpal-mode-map (make-keymap)) | |
914 (suppress-keymap gnus-carpal-mode-map) | |
915 (define-key gnus-carpal-mode-map " " 'gnus-carpal-select) | |
916 (define-key gnus-carpal-mode-map "\r" 'gnus-carpal-select) | |
917 (define-key gnus-carpal-mode-map gnus-mouse-2 'gnus-carpal-mouse-select)) | |
918 | |
919 (defun gnus-carpal-mode () | |
920 "Major mode for clicking buttons. | |
921 | |
922 All normal editing commands are switched off. | |
923 \\<gnus-carpal-mode-map> | |
924 The following commands are available: | |
925 | |
926 \\{gnus-carpal-mode-map}" | |
927 (interactive) | |
928 (kill-all-local-variables) | |
929 (setq mode-line-modified "-- ") | |
930 (setq major-mode 'gnus-carpal-mode) | |
931 (setq mode-name "Gnus Carpal") | |
932 (setq mode-line-process nil) | |
933 (use-local-map gnus-carpal-mode-map) | |
934 (buffer-disable-undo (current-buffer)) | |
935 (setq buffer-read-only t) | |
936 (make-local-variable 'gnus-carpal-attached-buffer) | |
937 (run-hooks 'gnus-carpal-mode-hook)) | |
938 | |
939 (defun gnus-carpal-setup-buffer (type) | |
940 (let ((buffer (symbol-value (intern (format "gnus-carpal-%s-buffer" type))))) | |
941 (if (get-buffer buffer) | |
942 () | |
943 (save-excursion | |
944 (set-buffer (get-buffer-create buffer)) | |
945 (gnus-carpal-mode) | |
946 (setq gnus-carpal-attached-buffer | |
947 (intern (format "gnus-%s-buffer" type))) | |
948 (gnus-add-current-to-buffer-list) | |
949 (let ((buttons (symbol-value | |
950 (intern (format "gnus-carpal-%s-buffer-buttons" | |
951 type)))) | |
952 (buffer-read-only nil) | |
953 button) | |
954 (while buttons | |
955 (setq button (car buttons) | |
956 buttons (cdr buttons)) | |
957 (if (stringp button) | |
958 (gnus-set-text-properties | |
959 (point) | |
960 (prog2 (insert button) (point) (insert " ")) | |
961 (list 'face gnus-carpal-header-face)) | |
962 (gnus-set-text-properties | |
963 (point) | |
964 (prog2 (insert (car button)) (point) (insert " ")) | |
965 (list 'gnus-callback (cdr button) | |
966 'face gnus-carpal-button-face | |
967 gnus-mouse-face-prop 'highlight)))) | |
968 (let ((fill-column (- (window-width) 2))) | |
969 (fill-region (point-min) (point-max))) | |
970 (set-window-point (get-buffer-window (current-buffer)) | |
971 (point-min))))))) | |
972 | |
973 (defun gnus-carpal-select () | |
974 "Select the button under point." | |
975 (interactive) | |
976 (let ((func (get-text-property (point) 'gnus-callback))) | |
977 (if (null func) | |
978 () | |
979 (pop-to-buffer (symbol-value gnus-carpal-attached-buffer)) | |
980 (call-interactively func)))) | |
981 | |
982 (defun gnus-carpal-mouse-select (event) | |
983 "Select the button under the mouse pointer." | |
984 (interactive "e") | |
985 (mouse-set-point event) | |
986 (gnus-carpal-select)) | |
987 | |
988 ;;; Allow redefinition of functions. | |
989 (gnus-ems-redefine) | |
990 | |
991 (provide 'gnus-salt) | |
992 | |
993 ;;; gnus-salt.el ends here |