Skip to content

Instantly share code, notes, and snippets.

@etherald
Created May 24, 2018 18:42
Show Gist options
  • Save etherald/55576fac9409f2ee20bc9e5e6e82ce1f to your computer and use it in GitHub Desktop.
Save etherald/55576fac9409f2ee20bc9e5e6e82ce1f to your computer and use it in GitHub Desktop.
two emacs lisp functions to lock buffers
(defun lock-view ()
"put all visible buffers in view mode"
(interactive)
(save-window-excursion
(mapcar (lambda (win)
(with-current-buffer (window-buffer win)
(unless buffer-read-only
(view-buffer (current-buffer)))))
(window-list))))
(defun lock-buffers-visiting-directory (dir)
(interactive "DDirectory:")
(save-window-excursion
(dolist (buf (buffer-list))
(when (and
(buffer-file-name buf)
(string-prefix-p dir (buffer-file-name buf)))
(with-current-buffer buf
(unless buffer-read-only
(view-buffer buf)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment