New icon indicates file is locked by another user.

This commit is contained in:
Matthew L. Fidler 2016-03-02 00:16:49 -06:00
parent b21c70f0e3
commit 12587ae51d
2 changed files with 77 additions and 44 deletions

View file

@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added ### Added
- Icon for files modified outside emacs (from Font Awesome). - Icon for files modified outside emacs (from Font Awesome).
- Icon for files that are being modified by another user (from Font Awesome).
## [0.3.0] ## [0.3.0]

View file

@ -209,6 +209,7 @@ This was stole/modified from `c-save-buffer-state'"
(save #xf0c7 FontAwesome) (save #xf0c7 FontAwesome)
(saved "" nil) (saved "" nil)
(modified-outside #xf071 FontAwesome) (modified-outside #xf071 FontAwesome)
(steal #xf21b FontAwesome)
(apple #xf179 FontAwesome) (apple #xf179 FontAwesome)
(win #xf17a FontAwesome) (win #xf17a FontAwesome)
;; FIXME: use lsb_release to determine Linux variant and choose appropriate icon ;; FIXME: use lsb_release to determine Linux variant and choose appropriate icon
@ -235,6 +236,7 @@ without the extension. And the third being the type of icon."
(const :tag "Saved" saved) (const :tag "Saved" saved)
(const :tag "Save" save) (const :tag "Save" save)
(const :tag "Modified Outside Emacs" modified-outside) (const :tag "Modified Outside Emacs" modified-outside)
(const :tag "Locked By Someone Else" steal)
(const :tag "Apple" apple) (const :tag "Apple" apple)
(const :tag "Windows" win) (const :tag "Windows" win)
(const :tag "Unix" unix)) (const :tag "Unix" unix))
@ -307,38 +309,59 @@ the icon."
'local-map 'local-map
'(keymap '(keymap
(mode-line keymap (mode-line keymap
(mouse-1 . mode-icons-save-or-revert-buffer) (mouse-1 . mode-icons-save-steal-or-revert-buffer)
(mouse-3 . mode-line-toggle-modified))) (mouse-3 . mode-line-toggle-modified)))
'help-echo 'mode-icons-modified-help-echo) 'help-echo 'mode-icons-modified-help-echo)
"List of text propeties to apply to read-only buffer indicator." "List of text propeties to apply to read-only buffer indicator."
:type '(repeat sexp) :type '(repeat sexp)
:group 'mode-icons) :group 'mode-icons)
(defun mode-icons-save-or-revert-buffer (event) (defun mode-icons-ask-user-about-lock (_file _other-user)
"Automatically steals lock."
t)
(defun mode-icons-save-steal-or-revert-buffer (event)
"Save buffer OR revert file from mode line. "Save buffer OR revert file from mode line.
Use EVENT to determine location." Use EVENT to determine location."
(interactive "e") (interactive "e")
(with-selected-window (posn-window (event-start event)) (with-selected-window (posn-window (event-start event))
(if (not (or (and (buffer-file-name) (file-remote-p buffer-file-name)) (let* ((bfn (buffer-file-name))
(verify-visited-file-modtime (current-buffer)))) (revert-p (not (or (and bfn (file-remote-p buffer-file-name))
(revert-buffer t t) (verify-visited-file-modtime (current-buffer)))))
(call-interactively (key-binding (where-is-internal 'save-buffer global-map t)))) (steal-p (and (not (or (and bfn (file-remote-p buffer-file-name))
(member (file-locked-p bfn) '(nil t)))))))
(cond
(revert-p (revert-buffer t t))
(steal-p
(message "To steal or ignore lock, start editing the file."))
(t (call-interactively (key-binding (where-is-internal 'save-buffer global-map t))))))
(force-mode-line-update))) (force-mode-line-update)))
(defun mode-icons-modified-help-echo (window _object _point) (defun mode-icons-modified-help-echo (window _object _point)
"Return help text specifying WINDOW's buffer modification status." "Return help text specifying WINDOW's buffer modification status."
(format "Buffer is %s\nmouse-1: %s Buffer\nmouse-3: Toggle modification state" (let* ((bfn (buffer-file-name))
(cond (revert-p (not (or (and bfn (file-remote-p buffer-file-name))
((not (or (and (buffer-file-name) (file-remote-p buffer-file-name)) (verify-visited-file-modtime (current-buffer)))))
(verify-visited-file-modtime (current-buffer)))) (steal-p (and (not (or (and bfn (file-remote-p buffer-file-name))
"modified outside of emacs!") (member (file-locked-p bfn) '(nil t))))))
((buffer-modified-p (window-buffer window)) (mod-p (buffer-modified-p (window-buffer window))))
"modified") (format "Buffer is %s\nmouse-1: %s Buffer\nmouse-3: Toggle modification state"
(t "unmodified")) (cond
(if (not (or (and (buffer-file-name) (file-remote-p buffer-file-name)) (steal-p
(verify-visited-file-modtime (current-buffer)))) "locked for editing by another user.")
"Revert" (revert-p
"Save"))) "modified outside of emacs!")
((buffer-modified-p (window-buffer window))
"modified")
(t "unmodified"))
(cond
(steal-p
"Echo about lock status of")
(revert-p
"Revert")
(mod-p
"Save")
(t "")))))
(defcustom mode-icons-read-only-text-properties (defcustom mode-icons-read-only-text-properties
'('mouse-face 'mode-line-highlight 'local-map '('mouse-face 'mode-line-highlight 'local-map
@ -396,8 +419,7 @@ everywhere else."
MODE should be a string, the name of the mode to propertize. MODE should be a string, the name of the mode to propertize.
ICON-SPEC should be a specification from `mode-icons'." ICON-SPEC should be a specification from `mode-icons'."
(mode-icons-save-buffer-state ;; Otherwise may cause issues with trasient mark mode (mode-icons-save-buffer-state ;; Otherwise may cause issues with trasient mark mode
(let (tmp) (cond
(cond
((and (stringp mode) (get-text-property 0 'mode-icons-p mode)) ((and (stringp mode) (get-text-property 0 'mode-icons-p mode))
mode) mode)
((not (nth 1 icon-spec)) ((not (nth 1 icon-spec))
@ -419,7 +441,7 @@ ICON-SPEC should be a specification from `mode-icons'."
(nth 1 icon-spec))) (nth 1 icon-spec)))
(put-text-property (point-min) (point-max) 'mode-icons-p t) (put-text-property (point-min) (point-max) 'mode-icons-p t)
(buffer-string))) (buffer-string)))
(t (propertize (format "%s" mode) 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)) 'mode-icons-p t)))))) (t (propertize (format "%s" mode) 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)) 'mode-icons-p t)))))
(defun mode-icons-get-icon-spec (mode) (defun mode-icons-get-icon-spec (mode)
"Get icon spec for MODE based on regular expression." "Get icon spec for MODE based on regular expression."
@ -574,29 +596,39 @@ ICON-SPEC should be a specification from `mode-icons'."
(defun mode-icons--modified-status () (defun mode-icons--modified-status ()
"Get modified status icon." "Get modified status icon."
(eval `(propertize (eval `(propertize
,(let ((mod (or (and (not (or (and (buffer-file-name) (file-remote-p buffer-file-name)) ,(or (ignore-errors
(verify-visited-file-modtime (current-buffer)))) (let* ((bfn (buffer-file-name))
"!") (nice-file-p (and (file-remote-p bfn)))
(format-mode-line "%1+"))) (mod (or (and (not (or nice-file-p (verify-visited-file-modtime (current-buffer))))
icon-spec) "!")
(setq mod (or (cond (and (not (or nice-file-p (member (file-locked-p bfn) '(nil t))))
((char-equal ?! (aref mod 0)) "s")
(if (setq icon-spec (mode-icons-get-icon-spec 'modified-outside)) (format-mode-line "%1+")))
(mode-icons-propertize-mode 'modified-outside icon-spec) icon-spec)
mod)) (setq mod (or (cond
((char-equal ?* (aref mod 0)) ((not (stringp mod)) "")
(if (setq icon-spec (mode-icons-get-icon-spec 'save)) ((char-equal ?s (aref mod 0))
(mode-icons-propertize-mode 'save icon-spec) (if (setq icon-spec (mode-icons-get-icon-spec 'steal))
mod)) (mode-icons-propertize-mode 'steal icon-spec)
(t mod))
(if (setq icon-spec (mode-icons-get-icon-spec 'saved)) ((char-equal ?! (aref mod 0))
(mode-icons-propertize-mode 'saved icon-spec) (if (setq icon-spec (mode-icons-get-icon-spec 'modified-outside))
mod))) (mode-icons-propertize-mode 'modified-outside icon-spec)
"")) mod))
(when (and mode-icons-modified-status-space ((char-equal ?* (aref mod 0))
(not (string= mod ""))) (if (setq icon-spec (mode-icons-get-icon-spec 'save))
(setq mod (concat mod " "))) (mode-icons-propertize-mode 'save icon-spec)
mod) mod))
(t
(if (setq icon-spec (mode-icons-get-icon-spec 'saved))
(mode-icons-propertize-mode 'saved icon-spec)
mod)))
""))
(when (and mode-icons-modified-status-space
(stringp mod)
(not (string= mod "")))
(setq mod (concat mod " ")))
mod)) "")
,@mode-icons-modified-text-properties))) ,@mode-icons-modified-text-properties)))
;; Based on rich-minority by Artur Malabarba ;; Based on rich-minority by Artur Malabarba