Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure if your function is really the cause of your problem. If it should be the case, the wrong usage of the <code>let*</code> that scottfrazer pointed out might be the cause. But you don't even need that <code>let*</code> (and <code>switch-to-buffer</code>) at all, because</p> <ol> <li>what you're trying to do is better done with Emacs' built in <code>save-excursion</code>, and</li> <li>you aren't actually switching the buffer ever.</li> </ol> <p>OTOH, you should have used <code>let</code> instead of the <code>setq</code>s in the lower half of your function, because <code>setq</code> will otherwise change a variable from an enclosing lexical scope. In this case you might very well have stomped over a <code>buffer</code> variable from the function that's executing the <code>desktop-save-hook</code> which is another potential cause of your problem.</p> <p>But you don't need those <code>let</code>s either because you can do the second loop with another <code>dolist</code>. You can get rid of those first 50 buffers that you don't want to loop over with <code>nthcdr</code>.</p> <p>Here's my improved version of <code>kill-old-buffers</code>:</p> <pre><code>(defun kill-old-buffers () "Kill buffers from end of buffer list (not used recently) until no more than 50 buffers are left. Remove temporary buffers first." (interactive) (save-excursion (dolist (buffer (buffer-list)) (if (or (string-match "^\*" (buffer-name buffer)) (string-match "\.hpp$" (buffer-name buffer))) (kill-buffer buffer))) (dolist (buffer (reverse (nthcdr 50 (buffer-list)))) (unless (eq buffer (current-buffer)) (kill-buffer buffer))))) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload