Start a section on "Tools to handle buffers and modes"

This commit is contained in:
Gerard Vermeulen 2023-12-17 14:00:21 +01:00
parent 86ddd09b24
commit 20f60c9330

View File

@ -1449,6 +1449,45 @@ on run
end run end run
#+end_src #+end_src
* Tools to handle buffers and modes
:PROPERTIES:
:CUSTOM_ID: sec:buffer-mode-tools
:END:
#+caption[Tools to handle buffers and modes]:
#+caption: Tools to handl buffers and modes.
#+name: lst:buffer-mode-tools
#+begin_src emacs-lisp -n :results silent
(defun set-all-buffers-with-modes (minor-mode value modes)
"Set MINOR-MODE to VALUE for all buffers with a mode derived from MODES."
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (and (derived-mode-p modes) (buffer-file-name))
(funcall minor-mode value)))))
(defun enable-ro-all-org-mode-buffers ()
"Enable `buffer-read-only' of all `org-mode' buffers."
(interactive)
(set-all-buffers-with-modes #'read-only-mode +1 '(org-mode))
(message "Enabled `buffer-read-only' of all `org-mode' buffers."))
(defun disable-ro-all-org-mode-buffers ()
"Disable `buffer-read-only' of all `org-mode' buffers."
(interactive)
(set-all-buffers-with-modes #'read-only-mode -1 '(org-mode))
(message "Disabled `buffer-read-only' of all `org-mode' buffers."))
(defun active-major-modes ()
"Return a list of active major modes found by iterating over all buffers."
(let (result)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(let ((mode major-mode))
(push mode result))))
(cl-sort (cl-remove-duplicates result) #'string-lessp)))
#+end_src
* Completion * Completion
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: sec:completion :CUSTOM_ID: sec:completion