feat(misc): add new siren-reopen helper function

This commit is contained in:
2022-08-25 22:59:09 +01:00
parent efccea6cbd
commit 06bf89af61
3 changed files with 41 additions and 10 deletions

View File

@@ -61,8 +61,9 @@
(require 'siren-explain-pause)
(require 'siren-lorem-ipsum)
(require 'siren-rand)
(require 'siren-restart-emacs)
(require 'siren-refine)
(require 'siren-reopen)
(require 'siren-restart-emacs)
(require 'siren-uuidgen)
(require 'siren-zone)

View File

@@ -76,15 +76,6 @@ Borrowed from: http://emacsredux.com/blog/2013/05/04/rename-file-and-buffer/"
(set-visited-file-name new-name)
(set-buffer-modified-p nil)))))))
(defun siren-reopen-current-file ()
"Reopen the current file."
(interactive)
(let ((filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(message "Buffer is not visiting a file!")
(kill-buffer)
(find-file filename))))
(defun siren-ignore-error-wrapper (fn)
"Funtion return new function that ignore errors.
The function wraps a function with `ignore-errors' macro."

View File

@@ -0,0 +1,39 @@
;;; siren-reopen.el --- jimeh's Emacs Siren: reopen helpers.
;;; Commentary:
;; Helper function to reopen buffers.
;;; Code:
(defun siren-reopen ()
"Reopen current buffer.
If the current buffer is backed by a readable file, it will kill
the buffer, and reopen the file.
If current buffer is the *scratch* buffer, it will create a new scratch buffer."
(interactive)
(cond (buffer-file-name (siren-reopen--current-file))
((string= (buffer-name) "*scratch*") (siren-reopen--scratch-buffer))))
(defun siren-reopen--current-file ()
"Reopen the current file."
(interactive)
(let ((filename buffer-file-name))
(if (not (file-readable-p filename))
(message "Buffer is not visiting a readable file!")
(kill-buffer)
(find-file filename))))
(defun siren-reopen--scratch-buffer ()
"Reopen the *scratch* buffer."
(interactive)
(let ((buffer (get-buffer "*scratch*")))
(when (and buffer (not (buffer-file-name buffer)))
(with-current-buffer buffer
(kill-buffer))
(scratch-buffer))))
(provide 'siren-reopen)
;;; siren-reopen.el ends here