I can not figure out why does when I factored out function it started to work wrong.
Here's the my function to kill all dired buffers, its bound to dired-mode-map
that work as expected and successfully kill all dired buffers when I invoke it in dired buffer:
(defun sandric/dired-kill-buffers ()
(interactive)
(mapc (lambda (buffer)
(when (eq 'dired-mode (buffer-local-value 'major-mode buffer))
(kill-buffer buffer)))
(buffer-list)))
I decided to factor out a function to kill all buffers by major mode name:
(defun sandric/kill-buffers-by-major-mode (mode-name)
"Kill open buffers by major mode name"
(interactive)
(mapc (lambda (buffer)
(when (eq mode-name (buffer-local-value 'major-mode buffer))
(kill-buffer buffer)))
(buffer-list)))
(defun sandric/dired-kill-buffers ()
(interactive)
(sandric/kill-buffers-by-major-mode 'dired-mode))
And now it works wrongly - it kills only current dired buffer and not killing parent ones. I can not understand why - it looks like nested function get bounded to current buffer and stops executing after it gets killed. Can anyone explain me why is it so and how to fix it?
C-h v mode-name