mirror of
https://github.com/ryuslash/mode-icons.git
synced 2024-11-22 01:50:28 +01:00
New icon indicates file is locked by another user.
This commit is contained in:
parent
b21c70f0e3
commit
12587ae51d
2 changed files with 77 additions and 44 deletions
|
@ -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]
|
||||||
|
|
||||||
|
|
|
@ -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."
|
||||||
|
(let* ((bfn (buffer-file-name))
|
||||||
|
(revert-p (not (or (and bfn (file-remote-p buffer-file-name))
|
||||||
|
(verify-visited-file-modtime (current-buffer)))))
|
||||||
|
(steal-p (and (not (or (and bfn (file-remote-p buffer-file-name))
|
||||||
|
(member (file-locked-p bfn) '(nil t))))))
|
||||||
|
(mod-p (buffer-modified-p (window-buffer window))))
|
||||||
(format "Buffer is %s\nmouse-1: %s Buffer\nmouse-3: Toggle modification state"
|
(format "Buffer is %s\nmouse-1: %s Buffer\nmouse-3: Toggle modification state"
|
||||||
(cond
|
(cond
|
||||||
((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-p
|
||||||
"modified outside of emacs!")
|
"modified outside of emacs!")
|
||||||
((buffer-modified-p (window-buffer window))
|
((buffer-modified-p (window-buffer window))
|
||||||
"modified")
|
"modified")
|
||||||
(t "unmodified"))
|
(t "unmodified"))
|
||||||
(if (not (or (and (buffer-file-name) (file-remote-p buffer-file-name))
|
(cond
|
||||||
(verify-visited-file-modtime (current-buffer))))
|
(steal-p
|
||||||
"Revert"
|
"Echo about lock status of")
|
||||||
"Save")))
|
(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,7 +419,6 @@ 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)
|
||||||
|
@ -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,12 +596,21 @@ 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)))
|
||||||
|
(mod (or (and (not (or nice-file-p (verify-visited-file-modtime (current-buffer))))
|
||||||
"!")
|
"!")
|
||||||
|
(and (not (or nice-file-p (member (file-locked-p bfn) '(nil t))))
|
||||||
|
"s")
|
||||||
(format-mode-line "%1+")))
|
(format-mode-line "%1+")))
|
||||||
icon-spec)
|
icon-spec)
|
||||||
(setq mod (or (cond
|
(setq mod (or (cond
|
||||||
|
((not (stringp mod)) "")
|
||||||
|
((char-equal ?s (aref mod 0))
|
||||||
|
(if (setq icon-spec (mode-icons-get-icon-spec 'steal))
|
||||||
|
(mode-icons-propertize-mode 'steal icon-spec)
|
||||||
|
mod))
|
||||||
((char-equal ?! (aref mod 0))
|
((char-equal ?! (aref mod 0))
|
||||||
(if (setq icon-spec (mode-icons-get-icon-spec 'modified-outside))
|
(if (setq icon-spec (mode-icons-get-icon-spec 'modified-outside))
|
||||||
(mode-icons-propertize-mode 'modified-outside icon-spec)
|
(mode-icons-propertize-mode 'modified-outside icon-spec)
|
||||||
|
@ -594,9 +625,10 @@ ICON-SPEC should be a specification from `mode-icons'."
|
||||||
mod)))
|
mod)))
|
||||||
""))
|
""))
|
||||||
(when (and mode-icons-modified-status-space
|
(when (and mode-icons-modified-status-space
|
||||||
|
(stringp mod)
|
||||||
(not (string= mod "")))
|
(not (string= mod "")))
|
||||||
(setq mod (concat mod " ")))
|
(setq mod (concat mod " ")))
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue