From b61d71e44f34c887107b0ca84371c67b904426df Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Tue, 23 Jul 2013 03:10:54 +0200 Subject: [PATCH] lisp/desktop.el: Simplify. (desktop-clear): Simplify; remove useless checks against invalid buffer names. (desktop-list*): Use cl-list*. (desktop-buffer-info, desktop-create-buffer): Simplify. --- lisp/ChangeLog | 7 ++++++ lisp/desktop.el | 65 ++++++++++++++++++------------------------------- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 597c50899c0..b30163526b1 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2013-07-23 Juanma Barranquero + + * desktop.el (desktop-clear): Simplify; remove useless checks + against invalid buffer names. + (desktop-list*): Use cl-list*. + (desktop-buffer-info, desktop-create-buffer): Simplify. + 2013-07-23 Leo Liu * bookmark.el (bookmark-make-record): Restore NAME as a default diff --git a/lisp/desktop.el b/lisp/desktop.el index 57a139ee7ee..666be7efee3 100644 --- a/lisp/desktop.el +++ b/lisp/desktop.el @@ -644,22 +644,17 @@ Furthermore, it clears the variables listed in `desktop-globals-to-clear'." (if (symbolp var) (eval `(setq-default ,var nil)) (eval `(setq-default ,(car var) ,(cdr var))))) - (let ((buffers (buffer-list)) - (preserve-regexp (concat "^\\(" + (let ((preserve-regexp (concat "^\\(" (mapconcat (lambda (regexp) (concat "\\(" regexp "\\)")) desktop-clear-preserve-buffers "\\|") "\\)$"))) - (while buffers - (let ((bufname (buffer-name (car buffers)))) - (or - (null bufname) - (string-match-p preserve-regexp bufname) - ;; Don't kill buffers made for internal purposes. - (and (not (equal bufname "")) (eq (aref bufname 0) ?\s)) - (kill-buffer (car buffers)))) - (setq buffers (cdr buffers)))) + (dolist (buffer (buffer-list)) + (let ((bufname (buffer-name buffer))) + (unless (or (eq (aref bufname 0) ?s) ;; Don't kill internal buffers + (string-match-p preserve-regexp bufname)) + (kill-buffer buffer))))) (delete-other-windows)) ;; ---------------------------------------------------------------------------- @@ -696,15 +691,7 @@ is nil, ask the user where to save the desktop." ;; ---------------------------------------------------------------------------- (defun desktop-list* (&rest args) - (if (null (cdr args)) - (car args) - (setq args (nreverse args)) - (let ((value (cons (nth 1 args) (car args)))) - (setq args (cdr (cdr args))) - (while args - (setq value (cons (car args) value)) - (setq args (cdr args))) - value))) + (and args (cl-list* args))) ;; ---------------------------------------------------------------------------- (defun desktop-buffer-info (buffer) @@ -736,16 +723,14 @@ is nil, ask the user where to save the desktop." (when (functionp desktop-save-buffer) (funcall desktop-save-buffer desktop-dirname)) ;; local variables - (let ((locals desktop-locals-to-save) - (loclist (buffer-local-variables)) - (ll)) - (while locals - (let ((here (assq (car locals) loclist))) - (if here - (setq ll (cons here ll)) - (when (member (car locals) loclist) - (setq ll (cons (car locals) ll))))) - (setq locals (cdr locals))) + (let ((loclist (buffer-local-variables)) + (ll nil)) + (dolist (local desktop-locals-to-save) + (let ((here (assq local loclist))) + (cond (here + (push here ll)) + ((member local loclist) + (push local ll))))) ll))) ;; ---------------------------------------------------------------------------- @@ -1748,17 +1733,15 @@ integer, start a new timer to call `desktop-auto-save' in that many seconds." (set-mark desktop-buffer-mark))) ;; Never override file system if the file really is read-only marked. (when desktop-buffer-read-only (setq buffer-read-only desktop-buffer-read-only)) - (while desktop-buffer-locals - (let ((this (car desktop-buffer-locals))) - (if (consp this) - ;; an entry of this form `(symbol . value)' - (progn - (make-local-variable (car this)) - (set (car this) (cdr this))) - ;; an entry of the form `symbol' - (make-local-variable this) - (makunbound this))) - (setq desktop-buffer-locals (cdr desktop-buffer-locals)))))))) + (dolist (this desktop-buffer-locals) + (if (consp this) + ;; an entry of this form `(symbol . value)' + (progn + (make-local-variable (car this)) + (set (car this) (cdr this))) + ;; an entry of the form `symbol' + (make-local-variable this) + (makunbound this)))))))) ;; ---------------------------------------------------------------------------- ;; Backward compatibility -- update parameters to 205 standards. -- 2.39.2