viernes, 26 de septiembre de 2025

Actualizar buffer Emacs con F5

 

 Para actualizar un buffer a su nueva versión en Emacs (linux), añadir lo siguiente al archivo ~/.emacs

 
(defun reload-file-preserve-point ()
  "Revert the current buffer to the file on disk WITHOUT asking, preserving point.
This will discard any unsaved changes and clear the undo history."
  (interactive)
  (unless buffer-file-name
    (user-error "Buffer is not visiting a file"))
  (save-excursion
    ;; revert-buffer: (revert-buffer IGNORE-AUTO NOCONFIRM PRESERVE-MODES)
    (revert-buffer t t t)
    (setq buffer-undo-list nil)
    (message "Buffer reverted (no prompt; undo cleared)")))

 

Y si, además, se quiere que esto corra con la tecla F5, añadir también lo siguiente:


(global-set-key (kbd "<f5>") 'reload-file-preserve-point)


No hay comentarios: