1

The modeline at the bottom already displays valuable information about the current buffer, like the EOL type (LF), the encoding (UTF-8)…

Now when I open a file, I would find it very handy to also display its date-time info (atime, ctime, mtime), preferably in a human format to know at a glimpse if I'm about to edit an old or a recent document.

2
  • How do you propose to get that information, e.g., by calling ls with the applicable switch(es) and converting the output to your human readable format? And, does that need to happen three individual times to get each of the the proposed values, or can all three values be extracted with a sole call using ls with the appropriate switch(es)? [... thinking about efficiency here ...] And, do you really want Emacs to perform those calls every time you type a key or move the cursor, or when you are scrolling through the text / screen (up/down)...? – lawlist Mar 25 at 2:34
  • @lawlist:file-attributes and related functions can be used to get that information. IIUC, the modeline changes only when first opening the file - no need to change it on every key press or cursor motion. When the buffer is saved, the file will get a new mod/access time and next time it is opened, the new values will be shown. The access time may be indeed useless: it will show pretty much the current time, since emacs just accessed it, unless there is another hook that can be run from find-file before the file is opened. My (partial) answer just deals with modtime. – NickD Mar 25 at 14:44
0

[Partial answer: how to get the information and turn it into a string. What it does not do (yet?) is add it to the modeline; but I believe (untested and therefore maybe baseless) that this is fundamentally sound]

The following function can be used e.g. in the find-file-hook to retrieve the information needed and turn it into a string - it only does it for mtime, but the others can be added without much difficulty (the only problem is that they are relatively long strings, so you may run out of space in the mode line):

(defun ndk/file-mtime ()
   (let* ((fname (buffer-file-name))
          (mtime (file-attribute-modification-time
                      (file-attributes fname))))
     (when mtime
        (format-time-string "%Y-%m-%dT%H:%M:%S" mtime))))

What remains to be done is to write a function to setq the variable mode-line-format to something that includes that information (TBD) - setting that variable makes it buffer-local which is what you want - and then adding the resulting function to find-file-hook. There is a section in the Emacs Lisp manual (C-h i g(elisp)mode line format) that explains how to set the variable, but it is somewhat complicated and I have not had the time to implement that. Feel free to do so and either submit an edit to this answer, or provide your own answer to complete this one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.