0

I tried running M-x eval-buffer to reload my init.el, which looks like this (point was at top, most irrelevant commented-out sections trimmed):

(global-set-key (kbd "C-c l") #'org-store-link)
(global-set-key (kbd "C-c a") #'org-agenda)
(global-set-key (kbd "C-c c") #'org-capture)

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
;; Bootstrap 'use-package'
(unless (package-installed-p 'use-package)
        (package-refresh-contents)
        (package-install 'use-package))
(eval-when-compile (require 'use-package))

;; Use use-package to download and load theme
(use-package dracula-theme
  :ensure t
  :config (load-theme 'dracula t))

(add-hook 'emacs-lisp-mode-hook 'paredit-mode)

(add-hook 'org-mode-hook #'visual-fill-column-mode)

(desktop-change-dir "~/.emacs.d/desktop")
(desktop-save-mode 1)

(eval-after-load 'org (define-key org-mode-map (kbd "C-M-i") 'pcomplete))

; This gets syntax-highlighted strangely as though the single quotes stop the comments
;;   ;; Rebind the 'd' key in org-agenda (default: `org-agenda-day-view').

;; Refresh org-agenda after rescheduling a task.
(defun org-agenda-refresh ()
  "Refresh all `org-agenda' buffers."
  (dolist (buffer (buffer-list))
    (with-current-buffer buffer
      (when (derived-mode-p 'org-agenda-mode)
        (org-agenda-maybe-redo)))))

(defadvice org-schedule (after refresh-agenda activate)
  "Refresh org-agenda."
  (org-agenda-refresh))

(setq org-read-date-prefer-future 'time)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(fill-column 90)
 '(git-commit-summary-max-length 50)
 '(org-agenda-custom-commands
   '(("n" "Agenda and my (or unassigned) TODOs"
      ((agenda "" nil)
       (tags-todo "<irrelevant search string>" nil))
      nil)))
 '(org-agenda-files '("~/org/agenda.org"))
 '(org-log-into-drawer t)
 '(package-selected-packages
   '(visual-fill-column paredit flycheck-clj-kondo org-recur cider magit use-package dracula-theme))
 '(save-place-mode t)
 '(visual-fill-column-enable-sensible-window-split nil))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

However, I got a prompt asking if I really wanted to kill the modified init.el buffer; when I answered no, it had to recreate the buffer by "reading killed buffer" (presumably from the kill ring). When I tried it again, it instead picked a different modified buffer (an Org file) to kill and recreate when I answered no again.

Why is it even killing any buffers at all? How am I actually supposed to just do a simple reload of minor changes, if eval-buffer is so wildly dangerous?

@whitetrillium suggested setting a breakpoint. Call stack from eval-buffer up looks like this:

* kill-buffer(#<buffer  *temp*>)
  #f(compiled-function () #<bytecode -0x1c1d6e334ba0c627>)()
  package-load-descriptor("/Users/ntuggy/.emacs.d/elpa/bind-key-20220910.2157")
  package-load-all-descriptors()
  package-initialize()
  eval-buffer()  ; Reading at buffer position 255

Nothing in the elisp source for that package explains why kill-buffer is getting called.

14
  • 1
    I see nothing suspicious in what you have provided. I would suggest M-x debug-on-entry RET kill-buffer. And do M-x eval-buffer again.
    – user31220
    Sep 26, 2022 at 16:35
  • @whitetrillium Thanks for the suggestion! I think that narrows it down, but I'm still puzzled. Sep 26, 2022 at 16:55
  • The backtrace shows that the *temp* buffer is getting killed, which is probably OK. What happens if you continue with c? Keep continuing until an interesting buffer is killed. It's that backtrace that you want.
    – NickD
    Sep 26, 2022 at 18:15
  • 1
    What exact version of Emacs are you using (including where you obtained the executable), on what platform? Can you reproduce this with emacs -Q (to skip any bugs in things installed at the system level)? Sep 26, 2022 at 18:45
  • 1
    Oh, I just realized from the trace you posted earlier that the problem is happening after package-initialize has loaded some code from the packages you have installed. So the bug is likely in the initialization code of one of these packages. And so to find it you'll probably need to figure out exactly what's getting loaded. Maybe try copying your .emacs.d and doing a binary search eliminating half the packages until you find the one problematic package (hoping it's a single package and not a combination). Sep 26, 2022 at 21:19

1 Answer 1

1

The problematic line is this:

(desktop-change-dir "~/.emacs.d/desktop")

This forces a reload of buffers because it saves the desktop and reloads it, even though all that's desired is to set the default path. For that, this correctly loads and saves the desktop without killing any buffers:

(setq desktop-path (list "~/.emacs.d/desktop"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.