"Touch" current file in emacs

Maybe more keystrokes than a custom function, but you can do this out the box with C-u M-~ then C-x C-s.

M-~ is bound by default to not-modified, which clears the buffer's modification flag, unless you call it with an argument (C-u prefix), in which case it does the opposite. Then just save the buffer.


Of course, this assumes that you have a command named touch on your path.

(defun touch ()
     "updates mtime on the file for the current buffer"
     (interactive)
     (shell-command (concat "touch " (shell-quote-argument (buffer-file-name))))
     (clear-visited-file-modtime))

In dired-mode there is a touch command bound by default to T. That command isn't so easy to use though because it prompts the user for a timestamp. I suppose that's very general, but it isn't a very convenient way to do what is typically intended by "touch."

Tags:

Emacs