Better powerline support

This commit is contained in:
Matthew Fidler 2016-04-04 10:41:20 -05:00
parent 8897af5b4a
commit 6ebd76ab71

View file

@ -622,16 +622,12 @@ When nil, don't stop the gimp inferior mode.")
(defvar mode-icons--stop-gimp-timer nil) (defvar mode-icons--stop-gimp-timer nil)
(defun mode-icons--pop-to-buffer-same-window (_buffer &optional _norecord)
"Ignore `pop-to-buffer-same-window' command."
t)
(defun mode-icons--start-gimp-inferior () (defun mode-icons--start-gimp-inferior ()
"GIMP inferior process." "GIMP inferior process."
(interactive) (interactive)
(when (file-exists-p mode-icons--gimp) (when (file-exists-p mode-icons--gimp)
(unless (get-buffer "*mode-icons-gimp*") (unless (get-buffer "*mode-icons-gimp*")
(letf (((symbol-function 'pop-to-buffer-same-window) #'mode-icons--pop-to-buffer-same-window)) (cl-letf (((symbol-function 'pop-to-buffer-same-window) (lambda(&rest _ignore))))
(save-excursion (save-excursion
(run-scheme (format "\"%s\" %s" mode-icons--gimp mode-icons--gimp-inferior-args)))) (run-scheme (format "\"%s\" %s" mode-icons--gimp mode-icons--gimp-inferior-args))))
(with-current-buffer (get-buffer "*scheme*") (with-current-buffer (get-buffer "*scheme*")
@ -648,24 +644,9 @@ When nil, don't stop the gimp inferior mode.")
(and (setq buf (get-buffer "*mode-icons-gimp*")) (and (setq buf (get-buffer "*mode-icons-gimp*"))
(with-current-buffer buf (with-current-buffer buf
(goto-char (point-min)) (goto-char (point-min))
(ignore-errors (comint-send-string "\n"))
(when (re-search-forward "ts>" nil t) (when (re-search-forward "ts>" nil t)
(setq mode-icons--gimp-ready-p t)))))))) (setq mode-icons--gimp-ready-p t))))))))
(defun mode-icons--process-gimp (scm)
"Process gimp SCM (scheme)."
(when mode-icons--stop-gimp-timer
(cancel-timer mode-icons--stop-gimp-timer))
(when (file-exists-p mode-icons--gimp)
(if (mode-icons--gimp-ready-p)
(progn
(comint-send-string
(with-current-buffer (get-buffer "*mode-icons-gimp*"))
(concat scm "\n"))
(when mode-icons--stop-gimp-after
(setq mode-icons--stop-gimp-timer (run-with-timer mode-icons--stop-gimp-after nil #'mode-icons-stop-gimp-inferior))))
(run-with-idle-timer 1 nil #'mode-icons--process-gimp scm))))
(defvar mode-icons--stop-gimp-inferior nil) (defvar mode-icons--stop-gimp-inferior nil)
(defun mode-icons--stop-gimp-inferior () (defun mode-icons--stop-gimp-inferior ()
"Stop the inferior gimp process." "Stop the inferior gimp process."
@ -683,6 +664,20 @@ When nil, don't stop the gimp inferior mode.")
(kill-buffer (get-buffer "*mode-icons-gimp*"))) (kill-buffer (get-buffer "*mode-icons-gimp*")))
(t (run-with-idle-timer 1 nil #'mode-icons--stop-gimp-inferior)))))) (t (run-with-idle-timer 1 nil #'mode-icons--stop-gimp-inferior))))))
(defun mode-icons--process-gimp (scm)
"Process gimp SCM (scheme)."
(when mode-icons--stop-gimp-timer
(cancel-timer mode-icons--stop-gimp-timer))
(when (file-exists-p mode-icons--gimp)
(if (mode-icons--gimp-ready-p)
(progn
(comint-send-string
(with-current-buffer (get-buffer "*mode-icons-gimp*"))
(concat scm "\n"))
(when mode-icons--stop-gimp-after
(setq mode-icons--stop-gimp-timer (run-with-timer mode-icons--stop-gimp-after nil #'mode-icons--stop-gimp-inferior))))
(run-with-idle-timer 1 nil #'mode-icons--process-gimp scm))))
(defvar mode-icons--font-to-xpm-gimp-script (defvar mode-icons--font-to-xpm-gimp-script
(replace-regexp-in-string (replace-regexp-in-string
"[ \n\t]+" " " "[ \n\t]+" " "
@ -1174,10 +1169,14 @@ When DONT-UPDATE is non-nil, don't call `force-mode-line-update'"
(unless dont-update (unless dont-update
(force-mode-line-update))) (force-mode-line-update)))
(defun mode-icons--generate-major-mode-item () (defun mode-icons--generate-major-mode-item (&optional face)
"Give rich strings needed for `major-mode' viewing." "Give rich strings needed for `major-mode' viewing.
FACE is the face that the major mode item should be rendered in."
(let ((active (mode-icons--selected-window-active))) (let ((active (mode-icons--selected-window-active)))
(eval `(propertize ,(mode-icons--recolor-string (or mode-icons--mode-name mode-name)) (eval `(propertize ,(mode-icons--recolor-string (or mode-icons--mode-name mode-name) active face)
'face ',(or face
(and active 'mode-line)
'mode-line-inactive)
,@mode-icons-major-mode-base-text-properties)))) ,@mode-icons-major-mode-base-text-properties))))
;;; selected take from powerline ;;; selected take from powerline
@ -1423,7 +1422,10 @@ FACE is the face to render the icon in."
(defun mode-icons--mode-line-eol-desc (&optional string face) (defun mode-icons--mode-line-eol-desc (&optional string face)
"Modify `mode-line-eol-desc' to have icons. "Modify `mode-line-eol-desc' to have icons.
STRING is the string to modify, or if absent, the value from `mode-line-eol-desc'.
STRING is the string to modify, or if absent, the value from
`mode-line-eol-desc'.
FACE is the face that will be used to render the segment." FACE is the face that will be used to render the segment."
(let* ((str (or string (mode-line-eol-desc))) (let* ((str (or string (mode-line-eol-desc)))
(props (text-properties-at 0 str)) (props (text-properties-at 0 str))
@ -1586,7 +1588,16 @@ PAD is the padding around the minor modes."
(if mode-icons-mode (if mode-icons-mode
(powerline-raw (format-mode-line (mode-icons--generate-minor-mode-list face) face) face pad) (powerline-raw (format-mode-line (mode-icons--generate-minor-mode-list face) face) face pad)
(mode-icons--real-powerline-minor-modes face pad))) (mode-icons--real-powerline-minor-modes face pad)))
(fset 'powerline-minor-modes (symbol-function #'mode-icons--powerline-minor-modes)))) (declare-function mode-icons--real-powerline-major-mode "powerline")
(fset 'mode-icons--real-powerline-major-mode (symbol-function #'powerline-minor-modes))
(defun mode-icons--powerline-major-mode (&optional face pad)
"Powerline major modes is replaced by this function.
FACE is the face to use.
PAD is the padding around the minor modes."
(if mode-icons-mode
(powerline-raw (format-mode-line (mode-icons--generate-major-mode-item face) face) face pad)
(mode-icons--real-powerline-major-mode face pad)))
(fset 'powerline-major-mode (symbol-function #'mode-icons--powerline-major-mode))))
(eval-after-load 'emojify (eval-after-load 'emojify
'(progn '(progn