1 ;;; eudc-hotlist.el --- hotlist management for EUDC
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Oscar Figueiredo <oscar@cpe.fr>
7 ;; Maintainer: Pavel JanÃk <Pavel@Janik.cz>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; See the corresponding info file
34 (defvar eudc-hotlist-menu nil
)
35 (defvar eudc-hotlist-mode-map nil
)
36 (defvar eudc-hotlist-list-beginning nil
)
38 (defun eudc-hotlist-mode ()
39 "Major mode used to edit the hotlist of servers.
41 These are the special commands of this mode:
42 a -- Add a new server to the list.
43 d -- Delete the server at point from the list.
44 s -- Select the server at point.
45 t -- Transpose the server at point and the previous one
46 q -- Commit the changes and quit.
47 x -- Quit without commiting the changes."
49 (kill-all-local-variables)
50 (setq major-mode
'eudc-hotlist-mode
)
51 (setq mode-name
"EUDC-Servers")
52 (use-local-map eudc-hotlist-mode-map
)
53 (when (featurep 'xemacs
)
54 (setq mode-popup-menu eudc-hotlist-menu
)
55 (when (featurep 'menubar
)
56 (set-buffer-menubar current-menubar
)
57 (add-submenu nil
(cons "EUDC-Hotlist" (cdr (cdr eudc-hotlist-menu
))))))
58 (setq buffer-read-only t
)
59 (run-mode-hooks 'eudc-hotlist-mode-hook
))
62 (defun eudc-edit-hotlist ()
63 "Edit the hotlist of directory servers in a specialized buffer."
67 (switch-to-buffer (get-buffer-create "*EUDC Servers*"))
68 (setq buffer-read-only nil
)
72 (setq proto-col
(max (length (car entry
)) proto-col
))))
74 (setq proto-col
(+ 3 proto-col
))
75 (setq gap
(make-string (- proto-col
6) ?\
))
76 (insert " EUDC Servers\n"
79 "Server" gap
"Protocol\n"
80 "------" gap
"--------\n"
82 (setq eudc-hotlist-list-beginning
(point))
83 (mapc '(lambda (entry)
86 (insert (symbol-name (cdr entry
)) "\n"))
90 (defun eudc-hotlist-add-server ()
91 "Add a new server to the list after current one."
93 (if (not (eq major-mode
'eudc-hotlist-mode
))
94 (error "Not in a EUDC hotlist edit buffer"))
95 (let ((server (read-from-minibuffer "Server: "))
96 (protocol (completing-read "Protocol: "
97 (mapcar '(lambda (elt)
98 (cons (symbol-name elt
)
100 eudc-known-protocols
)))
101 (buffer-read-only nil
))
106 (insert protocol
"\n")))
108 (defun eudc-hotlist-delete-server ()
109 "Delete the server at point from the list."
111 (if (not (eq major-mode
'eudc-hotlist-mode
))
112 (error "Not in a EUDC hotlist edit buffer"))
113 (let ((buffer-read-only nil
))
116 (if (and (>= (point) eudc-hotlist-list-beginning
)
117 (looking-at "^\\([-.a-zA-Z:0-9]+\\)[ \t]+\\([a-zA-Z]+\\)"))
119 (error "No server on this line")))))
121 (defun eudc-hotlist-quit-edit ()
122 "Quit the hotlist editing mode and save changes to the hotlist."
124 (if (not (eq major-mode
'eudc-hotlist-mode
))
125 (error "Not in a EUDC hotlist edit buffer"))
127 (goto-char eudc-hotlist-list-beginning
)
128 (while (looking-at "^\\([-.a-zA-Z:0-9]+\\)[ \t]+\\([a-zA-Z]+\\)")
129 (setq hotlist
(cons (cons (match-string 1)
130 (intern (match-string 2)))
133 (if (not (looking-at "^[ \t]*$"))
134 (error "Malformed entry in hotlist, discarding edits"))
135 (setq eudc-server-hotlist
(nreverse hotlist
))
140 (defun eudc-hotlist-select-server ()
141 "Select the server at point as the current server."
143 (if (not (eq major-mode
'eudc-hotlist-mode
))
144 (error "Not in a EUDC hotlist edit buffer"))
147 (if (and (>= (point) eudc-hotlist-list-beginning
)
148 (looking-at "^\\([-.a-zA-Z:0-9]+\\)[ \t]+\\([a-zA-Z]+\\)"))
150 (eudc-set-server (match-string 1) (intern (match-string 2)))
151 (message "Current directory server is %s (%s)" eudc-server eudc-protocol
))
152 (error "No server on this line"))))
154 (defun eudc-hotlist-transpose-servers ()
155 "Swap the order of the server with the previous one in the list."
157 (if (not (eq major-mode
'eudc-hotlist-mode
))
158 (error "Not in a EUDC hotlist edit buffer"))
159 (let ((buffer-read-only nil
))
162 (if (and (>= (point) eudc-hotlist-list-beginning
)
163 (looking-at "^\\([-.a-zA-Z:0-9]+\\)[ \t]+\\([a-zA-Z]+\\)")
166 (looking-at "^\\([-.a-zA-Z:0-9]+\\)[ \t]+\\([a-zA-Z]+\\)")))
169 (transpose-lines 1))))))
171 (setq eudc-hotlist-mode-map
172 (let ((map (make-sparse-keymap)))
173 (define-key map
"a" 'eudc-hotlist-add-server
)
174 (define-key map
"d" 'eudc-hotlist-delete-server
)
175 (define-key map
"s" 'eudc-hotlist-select-server
)
176 (define-key map
"t" 'eudc-hotlist-transpose-servers
)
177 (define-key map
"q" 'eudc-hotlist-quit-edit
)
178 (define-key map
"x" 'kill-this-buffer
)
181 (defconst eudc-hotlist-menu
182 '("EUDC Hotlist Edit"
184 ["Add New Server" eudc-hotlist-add-server t
]
185 ["Delete Server" eudc-hotlist-delete-server t
]
186 ["Select Server" eudc-hotlist-select-server t
]
187 ["Transpose Servers" eudc-hotlist-transpose-servers t
]
188 ["Save and Quit" eudc-hotlist-quit-edit t
]
189 ["Exit without Saving" kill-this-buffer t
]))
191 (when (not (featurep 'xemacs
))
192 (easy-menu-define eudc-hotlist-emacs-menu
193 eudc-hotlist-mode-map
197 ;; arch-tag: 9b633ab3-6a6e-4b46-b12e-d96739a7e0e8
198 ;;; eudc-hotlist.el ends here