Mercurial > hg > xemacs-beta
comparison lisp/package-ui.el @ 321:19dcec799385 r21-0-58
Import from CVS: tag r21-0-58
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:46:44 +0200 |
parents | 512e409c26a2 |
children | 03446687b7cc |
comparison
equal
deleted
inserted
replaced
320:73c75c43c1f2 | 321:19dcec799385 |
---|---|
28 | 28 |
29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
30 ;; User-changeable variables: | 30 ;; User-changeable variables: |
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
32 | 32 |
33 (defvar pui-up-to-date-package-face nil | 33 (defgroup pui nil |
34 "The face to use for packages that are up-to-date.") | 34 "Conventient interface to the package system." |
35 | 35 :group 'package-tools |
36 (defvar pui-selected-package-face (get-face 'bold) | 36 :tag "Package User interface" |
37 "The face to use for selected packages. | 37 :prefix "pui-") |
38 Set this to `nil' to use the `default' face.") | 38 |
39 | 39 (defcustom pui-package-install-dest-dir nil |
40 (defvar pui-outdated-package-face (get-face 'red) | 40 "*If non-nil (Automatic) path to package tree to install packages in. |
41 "The face to use for outdated packages. | 41 Otherwise, use old path for installed packages and make a guess for |
42 Set this to `nil' to use the `default' face.") | 42 new ones." |
43 | 43 :group 'pui |
44 (defvar pui-uninstalled-package-face (get-face 'italic) | 44 :tag "Install Location" |
45 "The face to use for uninstalled packages. | 45 :type '(choice (const :tag "Automatic" nil) |
46 Set this to `nil' to use the `default' face.") | 46 (directory))) |
47 | 47 |
48 (defvar pui-list-verbose t | 48 (defcustom pui-list-verbose t |
49 "If non-nil, display verbose info in the package list buffer.") | 49 "*If non-nil, display verbose info in the package list buffer." |
50 :group 'pui | |
51 :tag "Verbose Listing" | |
52 :type 'boolean) | |
53 | |
54 (defcustom pui-up-to-date-package-face nil | |
55 "*The face to use for packages that are up-to-date." | |
56 :group 'pui | |
57 :type 'face) | |
58 | |
59 (defcustom pui-selected-package-face 'bold | |
60 "*The face to use for selected packages. | |
61 Set this to `nil' to use the `default' face." | |
62 :group 'pui | |
63 :type 'face) | |
64 | |
65 (defcustom pui-outdated-package-face 'red | |
66 "*The face to use for outdated packages. | |
67 Set this to `nil' to use the `default' face." | |
68 :group 'pui | |
69 :type 'face) | |
70 | |
71 (defcustom pui-uninstalled-package-face 'italic | |
72 "*The face to use for uninstalled packages. | |
73 Set this to `nil' to use the `default' face." | |
74 :group 'pui | |
75 :type 'face) | |
76 | |
77 | |
78 | |
50 | 79 |
51 (defvar pui-info-buffer "*Packages*" | 80 (defvar pui-info-buffer "*Packages*" |
52 "Buffer to use for displaying package information.") | 81 "Buffer to use for displaying package information.") |
53 | 82 |
54 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
69 (define-key m "v" 'pui-toggle-verbosity-redisplay) | 98 (define-key m "v" 'pui-toggle-verbosity-redisplay) |
70 (define-key m "d" 'pui-toggle-verbosity-redisplay) | 99 (define-key m "d" 'pui-toggle-verbosity-redisplay) |
71 (define-key m [return] 'pui-toggle-package-key) | 100 (define-key m [return] 'pui-toggle-package-key) |
72 (define-key m "x" 'pui-install-selected-packages) | 101 (define-key m "x" 'pui-install-selected-packages) |
73 (define-key m "I" 'pui-install-selected-packages) | 102 (define-key m "I" 'pui-install-selected-packages) |
103 (define-key m "r" 'pui-add-required-packages) | |
74 (define-key m "n" 'next-line) | 104 (define-key m "n" 'next-line) |
75 (define-key m "+" 'next-line) | 105 (define-key m "+" 'next-line) |
76 (define-key m "p" 'previous-line) | 106 (define-key m "p" 'previous-line) |
77 (define-key m "-" 'previous-line) | 107 (define-key m "-" 'previous-line) |
78 m) | 108 m) |
80 | 110 |
81 (defvar pui-package-keymap | 111 (defvar pui-package-keymap |
82 (let ((m (make-sparse-keymap))) | 112 (let ((m (make-sparse-keymap))) |
83 (set-keymap-name m 'pui-package-keymap) | 113 (set-keymap-name m 'pui-package-keymap) |
84 (define-key m 'button2 'pui-toggle-package-event) | 114 (define-key m 'button2 'pui-toggle-package-event) |
85 (define-key m 'button3 'pui-toggle-package-event) | 115 ;; We use a popup menu |
116 ;; (define-key m 'button3 'pui-toggle-package-event) | |
86 m) | 117 m) |
87 "Keymap to use over package names/descriptions.") | 118 "Keymap to use over package names/descriptions.") |
88 | 119 |
89 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
90 ;; End of variables | 121 ;; End of variables |
180 )) | 211 )) |
181 | 212 |
182 (defun pui-package-symbol-char (pkg-sym version) | 213 (defun pui-package-symbol-char (pkg-sym version) |
183 (progn | 214 (progn |
184 (if (package-get-info-find-package packages-package-list pkg-sym) | 215 (if (package-get-info-find-package packages-package-list pkg-sym) |
185 (if (package-get-installedp pkg-sym version) | 216 (let ((installed (package-get-key pkg-sym :version))) |
186 (list " " pui-up-to-date-package-face) | 217 (if (>= (if (stringp installed) |
187 (list "*" pui-outdated-package-face)) | 218 (string-to-number installed) |
219 installed) | |
220 (if (stringp version) | |
221 (string-to-number version) | |
222 version)) | |
223 (list " " pui-up-to-date-package-face) | |
224 (list "*" pui-outdated-package-face))) | |
188 (list "-" pui-uninstalled-package-face)) | 225 (list "-" pui-uninstalled-package-face)) |
189 )) | 226 )) |
190 | 227 |
191 (defun pui-update-package-display (extent &optional pkg-sym version) | 228 (defun pui-update-package-display (extent &optional pkg-sym version) |
192 "Update the package status for EXTENT. | 229 "Update the package status for EXTENT. |
207 (setq sym-char "+") | 244 (setq sym-char "+") |
208 ) | 245 ) |
209 (progn | 246 (progn |
210 (setq disp (pui-package-symbol-char pkg-sym version)) | 247 (setq disp (pui-package-symbol-char pkg-sym version)) |
211 (setq sym-char (car disp)) | 248 (setq sym-char (car disp)) |
212 (if (cdr disp) | 249 (if (car (cdr disp)) |
213 (set-extent-face extent (car (cdr disp))) | 250 (set-extent-face extent (get-face (car (cdr disp)))) |
214 (set-extent-face extent (get-face 'default))) | 251 (set-extent-face extent (get-face 'default))) |
215 )) | 252 )) |
216 (save-excursion | 253 (save-excursion |
217 (goto-char (extent-start-position extent)) | 254 (goto-char (extent-start-position extent)) |
218 (delete-char 1) | 255 (delete-char 1) |
299 (erase-buffer package-admin-temp-buffer) | 336 (erase-buffer package-admin-temp-buffer) |
300 ) | 337 ) |
301 (message "Installing selected packages ...") (sit-for 0) | 338 (message "Installing selected packages ...") (sit-for 0) |
302 (if (catch 'done | 339 (if (catch 'done |
303 (mapcar (lambda (pkg) | 340 (mapcar (lambda (pkg) |
304 (if (not (package-get-all pkg nil)) | 341 (if (not (package-get pkg nil nil |
342 pui-package-install-dest-dir)) | |
305 (throw 'done nil))) | 343 (throw 'done nil))) |
306 pui-selected-packages) | 344 pui-selected-packages) |
307 t) | 345 t) |
308 (progn | 346 (progn |
309 (pui-list-packages) | 347 (pui-list-packages) |
313 (clear-message) | 351 (clear-message) |
314 ) | 352 ) |
315 ) | 353 ) |
316 (error "No packages have been selected!")) | 354 (error "No packages have been selected!")) |
317 )) | 355 )) |
356 | |
357 (defun pui-add-required-packages () | |
358 "Select packages required by those already selected for installation." | |
359 (interactive) | |
360 (let ((tmpbuf "*Required-Packages*") do-select) | |
361 (if pui-selected-packages | |
362 (let ((dependencies | |
363 (delq nil (mapcar | |
364 (lambda (pkg) | |
365 (let ((installed | |
366 (package-get-key pkg :version)) | |
367 (current | |
368 (package-get-info-prop | |
369 (package-get-info-version | |
370 (package-get-info-find-package | |
371 package-get-base pkg) nil) | |
372 'version))) | |
373 (if (< (if (stringp installed) | |
374 (string-to-number installed) | |
375 installed) | |
376 (if (stringp current) | |
377 (string-to-number current) | |
378 current)) | |
379 pkg | |
380 nil))) | |
381 (package-get-dependencies pui-selected-packages))))) | |
382 ;; Don't change window config when asking the user if he really | |
383 ;; wants to add the packages. We do this to avoid messing up | |
384 ;; the window configuration if errors occur (we don't want to | |
385 ;; display random buffers in addition to the error buffer, if | |
386 ;; errors occur, which would normally be caused by display-buffer). | |
387 (save-window-excursion | |
388 (with-output-to-temp-buffer tmpbuf | |
389 (display-completion-list (sort | |
390 (mapcar #'(lambda (pkg) | |
391 (symbol-name pkg)) | |
392 dependencies) | |
393 'string<) | |
394 :activate-callback nil | |
395 :help-string "Required packages:\n" | |
396 :completion-string t)) | |
397 (setq tmpbuf (get-buffer-create tmpbuf)) | |
398 (display-buffer tmpbuf) | |
399 (setq do-select (y-or-n-p "Select these packages? ")) | |
400 (kill-buffer tmpbuf)) | |
401 (if do-select | |
402 (progn | |
403 (setq pui-selected-packages | |
404 (union pui-selected-packages dependencies)) | |
405 (map-extents #'(lambda (extent maparg) | |
406 (pui-update-package-display extent)) | |
407 nil nil nil nil nil 'pui) | |
408 (message "added dependencies")) | |
409 (clear-message))) | |
410 (error "No packages have been selected!")))) | |
318 | 411 |
319 (defun pui-help-echo (extent &optional force-update) | 412 (defun pui-help-echo (extent &optional force-update) |
320 "Display additional package info in the modeline. | 413 "Display additional package info in the modeline. |
321 EXTENT determines the package to display (the package information is | 414 EXTENT determines the package to display (the package information is |
322 attached to the extent as properties)." | 415 attached to the extent as properties)." |
369 available. | 462 available. |
370 | 463 |
371 Useful keys: | 464 Useful keys: |
372 | 465 |
373 `\\[pui-toggle-package-key]' to select/unselect the current package for installation. | 466 `\\[pui-toggle-package-key]' to select/unselect the current package for installation. |
467 `\\[pui-add-required-packages]' to add any packages required by those selected. | |
374 `\\[pui-install-selected-packages]' to install selected packages. | 468 `\\[pui-install-selected-packages]' to install selected packages. |
375 `\\[pui-display-info]' to display additional information about the package in the modeline. | 469 `\\[pui-display-info]' to display additional information about the package in the modeline. |
376 `\\[pui-list-packages]' to refresh the package list. | 470 `\\[pui-list-packages]' to refresh the package list. |
377 `\\[pui-toggle-verbosity-redisplay]' to toggle between a verbose and non-verbose display. | 471 `\\[pui-toggle-verbosity-redisplay]' to toggle between a verbose and non-verbose display. |
378 `\\[pui-quit]' to kill this buffer. | 472 `\\[pui-quit]' to kill this buffer. |
379 ") | 473 ") |
380 )) | 474 )) |
475 | |
476 (defvar pui-menu | |
477 '("Packages" | |
478 ["Select" pui-toggle-package-key t] | |
479 ["Info" pui-display-info t] | |
480 "---" | |
481 ["Add Required" pui-add-required-packages t] | |
482 ["Install Selected" pui-install-selected-packages t] | |
483 "---" | |
484 ["Verbose" pui-toggle-verbosity-redisplay | |
485 :active t :style toggle :selected pui-list-verbose] | |
486 ["Refresh" pui-list-packages t] | |
487 ["Help" pui-help t] | |
488 ["Quit" pui-quit t])) | |
489 | |
381 | 490 |
382 ;;;###autoload | 491 ;;;###autoload |
383 (defun pui-list-packages () | 492 (defun pui-list-packages () |
384 "List all packages and package information. | 493 "List all packages and package information. |
385 The package name, version, and description are displayed. From the displayed | 494 The package name, version, and description are displayed. From the displayed |
386 buffer, the user can see which packages are installed, which are not, and | 495 buffer, the user can see which packages are installed, which are not, and |
387 which are out-of-date (a newer version is available). The user can then | 496 which are out-of-date (a newer version is available). The user can then |
388 select packages for installation via the keyboard or mouse." | 497 select packages for installation via the keyboard or mouse." |
389 (interactive) | 498 (interactive) |
499 (package-get-require-base t) | |
390 (let ( (outbuf (get-buffer-create pui-info-buffer)) | 500 (let ( (outbuf (get-buffer-create pui-info-buffer)) |
391 (sep-string "===============================================================================\n") | 501 (sep-string "===============================================================================\n") |
392 start ) | 502 start ) |
393 (message "Creating package list ...") (sit-for 0) | 503 (message "Creating package list ...") (sit-for 0) |
394 (set-buffer outbuf) | 504 (set-buffer outbuf) |
450 (forward-line -1) | 560 (forward-line -1) |
451 (end-of-line) | 561 (end-of-line) |
452 (point))) | 562 (point))) |
453 ) | 563 ) |
454 (setq extent (make-extent b e)) | 564 (setq extent (make-extent b e)) |
455 (if (cdr disp) | 565 (if (car (cdr disp)) |
456 (set-extent-face extent (car (cdr disp))) | 566 (set-extent-face extent (get-face (car (cdr disp)))) |
457 (set-extent-face extent (get-face 'default))) | 567 (set-extent-face extent (get-face 'default))) |
458 (set-extent-property extent 'highlight t) | 568 (set-extent-property extent 'highlight t) |
459 (set-extent-property extent 'pui t) | 569 (set-extent-property extent 'pui t) |
460 (set-extent-property extent 'pui-package pkg-sym) | 570 (set-extent-property extent 'pui-package pkg-sym) |
461 (set-extent-property extent 'pui-info info) | 571 (set-extent-property extent 'pui-info info) |
472 (setq buffer-read-only t) | 582 (setq buffer-read-only t) |
473 (pop-to-buffer outbuf) | 583 (pop-to-buffer outbuf) |
474 (delete-other-windows) | 584 (delete-other-windows) |
475 (goto-char start) | 585 (goto-char start) |
476 (setq pui-selected-packages nil) ; Reset list | 586 (setq pui-selected-packages nil) ; Reset list |
587 (when (featurep 'menubar) | |
588 (set-buffer-menubar current-menubar) | |
589 (add-submenu '() pui-menu) | |
590 (setq mode-popup-menu pui-menu)) | |
477 (clear-message) | 591 (clear-message) |
478 ; (message (substitute-command-keys "Press `\\[pui-help]' for help.")) | 592 ; (message (substitute-command-keys "Press `\\[pui-help]' for help.")) |
479 )) | 593 )) |
480 | 594 |
595 | |
481 (provide 'package-ui) | 596 (provide 'package-ui) |
482 | 597 |
483 ;;; package-ui.el ends here | 598 ;;; package-ui.el ends here |