Mercurial > emacs
comparison lisp/desktop.el @ 51441:b9a57b098ab3
(desktop-create-buffer): Undo last change.
(desktop-kill, desktop-save, desktop-remove): Use expand-directory rather than
concat to construct desktop filename.
(desktop-kill, desktop-read, desktop-change-dir): Ensure desktop-dirname is a
directory name.
(desktop-change-dir): Fix bug when DIR was relative.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 03 Jun 2003 23:30:43 +0000 |
parents | 140113b35d70 |
children | 2c411b58af59 |
comparison
equal
deleted
inserted
replaced
51440:5c94c67cf9c1 | 51441:b9a57b098ab3 |
---|---|
392 If the desktop should be saved and `desktop-dirname' | 392 If the desktop should be saved and `desktop-dirname' |
393 is nil, ask the user where to save the desktop." | 393 is nil, ask the user where to save the desktop." |
394 (when | 394 (when |
395 (and | 395 (and |
396 desktop-enable | 396 desktop-enable |
397 (let ((exists (file-exists-p (concat desktop-dirname desktop-base-file-name)))) | 397 (let ((exists (file-exists-p (expand-file-name desktop-base-file-name desktop-dirname)))) |
398 (or | 398 (or |
399 (eq desktop-save 't) | 399 (eq desktop-save 't) |
400 (and exists (memq desktop-save '(ask-if-new if-exists))) | 400 (and exists (memq desktop-save '(ask-if-new if-exists))) |
401 (and | 401 (and |
402 (or | 402 (or |
403 (memq desktop-save '(ask ask-if-new)) | 403 (memq desktop-save '(ask ask-if-new)) |
404 (and exists (eq desktop-save 'ask-if-exists))) | 404 (and exists (eq desktop-save 'ask-if-exists))) |
405 (y-or-n-p "Save desktop? "))))) | 405 (y-or-n-p "Save desktop? "))))) |
406 (unless desktop-dirname | 406 (unless desktop-dirname |
407 (setq desktop-dirname | 407 (setq desktop-dirname |
408 (expand-file-name | 408 (file-name-as-directory |
409 (call-interactively | 409 (expand-file-name |
410 (lambda (dir) (interactive "DDirectory for desktop file: ") dir))))) | 410 (call-interactively |
411 (lambda (dir) (interactive "DDirectory for desktop file: ") dir)))))) | |
411 (condition-case err | 412 (condition-case err |
412 (desktop-save desktop-dirname) | 413 (desktop-save desktop-dirname) |
413 (file-error | 414 (file-error |
414 (unless (yes-or-no-p "Error while saving the desktop. Ignore? ") | 415 (unless (yes-or-no-p "Error while saving the desktop. Ignore? ") |
415 (signal (car err) (cdr err))))))) | 416 (signal (car err) (cdr err))))))) |
581 "Save the Desktop file. Parameter DIRNAME specifies where to save desktop." | 582 "Save the Desktop file. Parameter DIRNAME specifies where to save desktop." |
582 (interactive "DDirectory to save desktop file in: ") | 583 (interactive "DDirectory to save desktop file in: ") |
583 (run-hooks 'desktop-save-hook) | 584 (run-hooks 'desktop-save-hook) |
584 (setq dirname (file-name-as-directory (expand-file-name dirname))) | 585 (setq dirname (file-name-as-directory (expand-file-name dirname))) |
585 (save-excursion | 586 (save-excursion |
586 (let ((filename (concat dirname desktop-base-file-name)) | 587 (let ((filename (expand-file-name desktop-base-file-name dirname)) |
587 (info | 588 (info |
588 (mapcar | 589 (mapcar |
589 (function | 590 (function |
590 (lambda (b) | 591 (lambda (b) |
591 (set-buffer b) | 592 (set-buffer b) |
664 ;; ---------------------------------------------------------------------------- | 665 ;; ---------------------------------------------------------------------------- |
665 (defun desktop-remove () | 666 (defun desktop-remove () |
666 "Delete the Desktop file and inactivate the desktop system." | 667 "Delete the Desktop file and inactivate the desktop system." |
667 (interactive) | 668 (interactive) |
668 (if desktop-dirname | 669 (if desktop-dirname |
669 (let ((filename (concat desktop-dirname desktop-base-file-name))) | 670 (let ((filename (expand-file-name desktop-base-file-name desktop-dirname))) |
670 (setq desktop-dirname nil) | 671 (setq desktop-dirname nil) |
671 (if (file-exists-p filename) | 672 (if (file-exists-p filename) |
672 (delete-file filename))))) | 673 (delete-file filename))))) |
673 | |
674 ;; ---------------------------------------------------------------------------- | 674 ;; ---------------------------------------------------------------------------- |
675 ;;;###autoload | 675 ;;;###autoload |
676 (defun desktop-read () | 676 (defun desktop-read () |
677 "Read the Desktop file and the files it specifies. | 677 "Read the Desktop file and the files it specifies. |
678 This is a no-op when Emacs is running in batch mode. | 678 This is a no-op when Emacs is running in batch mode. |
686 (and | 686 (and |
687 dirs | 687 dirs |
688 (not | 688 (not |
689 (file-exists-p (expand-file-name desktop-base-file-name (car dirs))))) | 689 (file-exists-p (expand-file-name desktop-base-file-name (car dirs))))) |
690 (setq dirs (cdr dirs))) | 690 (setq dirs (cdr dirs))) |
691 (setq desktop-dirname (and dirs (expand-file-name (car dirs)))) | 691 (setq desktop-dirname (and dirs (file-name-as-directory (expand-file-name (car dirs))))) |
692 (if desktop-dirname | 692 (if desktop-dirname |
693 (let ((desktop-first-buffer nil)) | 693 (let ((desktop-first-buffer nil)) |
694 ;; Evaluate desktop buffer. | 694 ;; Evaluate desktop buffer. |
695 (load (expand-file-name desktop-base-file-name desktop-dirname) t t t) | 695 (load (expand-file-name desktop-base-file-name desktop-dirname) t t t) |
696 ;; `desktop-create-buffer' puts buffers at end of the buffer list. | 696 ;; `desktop-create-buffer' puts buffers at end of the buffer list. |
725 (defun desktop-change-dir (dir) | 725 (defun desktop-change-dir (dir) |
726 "Save and clear the desktop, then load the desktop from directory DIR. | 726 "Save and clear the desktop, then load the desktop from directory DIR. |
727 However, if `desktop-enable' was nil at call, don't save the old desktop. | 727 However, if `desktop-enable' was nil at call, don't save the old desktop. |
728 This function always sets `desktop-enable' to t." | 728 This function always sets `desktop-enable' to t." |
729 (interactive "DNew directory: ") | 729 (interactive "DNew directory: ") |
730 (setq dir (file-name-as-directory (expand-file-name dir desktop-dirname))) | |
730 (desktop-kill) | 731 (desktop-kill) |
731 (desktop-clear) | 732 (desktop-clear) |
732 (cd dir) | |
733 (setq desktop-enable t) | 733 (setq desktop-enable t) |
734 (let ((desktop-path '("."))) | 734 (let ((desktop-path (list dir)) |
735 (desktop-read) | 735 (default-directory dir)) |
736 ;; Set `desktop-dirname' even in no desktop file was found | 736 (desktop-read)) |
737 (setq desktop-dirname (expand-file-name dir)))) | 737 ;; Set `desktop-dirname' even in no desktop file was found |
738 | 738 (setq desktop-dirname dir)) |
739 ;; ---------------------------------------------------------------------------- | 739 ;; ---------------------------------------------------------------------------- |
740 ;;;###autoload | 740 ;;;###autoload |
741 (defun desktop-save-in-load-dir () | 741 (defun desktop-save-in-load-dir () |
742 "Save desktop in directory from which it was loaded." | 742 "Save desktop in directory from which it was loaded." |
743 (interactive) | 743 (interactive) |
744 (if desktop-dirname | 744 (if desktop-dirname |
873 ;; allow `default-directory' to change. Therefore we save current buffer. | 873 ;; allow `default-directory' to change. Therefore we save current buffer. |
874 (save-current-buffer | 874 (save-current-buffer |
875 (let ( | 875 (let ( |
876 (buffer-list (buffer-list)) | 876 (buffer-list (buffer-list)) |
877 (hlist desktop-buffer-handlers) | 877 (hlist desktop-buffer-handlers) |
878 (desktop-first-buffer) | |
879 (result) | 878 (result) |
880 (handler) | 879 (handler) |
881 ) | 880 ) |
882 ;; Call desktop-buffer-handlers to create buffer. | 881 ;; Call desktop-buffer-handlers to create buffer. |
883 (while (and (not result) hlist) | 882 (while (and (not result) hlist) |
907 (mapcar | 906 (mapcar |
908 #'(lambda (minor-mode) | 907 #'(lambda (minor-mode) |
909 (when (functionp minor-mode) (funcall minor-mode 1))) | 908 (when (functionp minor-mode) (funcall minor-mode 1))) |
910 desktop-buffer-minor-modes))) | 909 desktop-buffer-minor-modes))) |
911 ;; Even though point and mark are non-nil when written by `desktop-save' | 910 ;; Even though point and mark are non-nil when written by `desktop-save' |
912 ;; they may be modified by mandlers wanting to set point or mark themselves. | 911 ;; they may be modified by handlers wanting to set point or mark themselves. |
913 (when desktop-buffer-point (goto-char desktop-buffer-point)) | 912 (when desktop-buffer-point (goto-char desktop-buffer-point)) |
914 (when desktop-buffer-mark | 913 (when desktop-buffer-mark |
915 (if (consp desktop-buffer-mark) | 914 (if (consp desktop-buffer-mark) |
916 (progn | 915 (progn |
917 (set-mark (car desktop-buffer-mark)) | 916 (set-mark (car desktop-buffer-mark)) |