Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have found myself switching between Emacs and a shell several times today, just to check the file permissions before saving the file I have open in Emacs.

Needless to say, this is suboptimal and provides ample opportunity for improvement.

I would like to have the modeline show the permission bits, sort of like;

-:--- .netrc 0600 .... further modeline stuff ....

The closest I have seen to accomplish this goal is on the emacs-fu blog, but I would like a more generic solution than just checking whether the file is read only.

How would I achieve this?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I played with it a bit and got this to work for me:

;; New variable to contain buffer file permission format construct.
(defvar my-mode-line-buffer-permissions
  '(:eval (when (buffer-file-name) (format " %04o" (file-modes (buffer-file-name))))))
;; The variable must be marked as "risky" (see C-h v mode-line-format)
(put 'my-mode-line-buffer-permissions 'risky-local-variable t)
;; And finally add it right after the file name:
(setq-default
 mode-line-buffer-identification
 (append mode-line-buffer-identification (list 'my-mode-line-buffer-permissions)))

My mode line now says:

-uu-:---F1  .emacs       0644   Top L1     (Emacs-Lisp)--------------
share|improve this answer
    
Just perfect! I'm going to do nothing more the rest of the day than open files in emacs and look at the modeline –  Steen Feb 11 '13 at 12:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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