From 456dc620512a43177654d310ecabe327eb832f12 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 29 May 2018 14:50:42 +0200 Subject: [PATCH] Fix compile-time void-function errors from modeline --- core/core-ui.el | 70 +++++++++++++++++------------- modules/ui/doom-modeline/config.el | 12 ++--- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/core/core-ui.el b/core/core-ui.el index 56e5f2559..166dbfd97 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -111,36 +111,40 @@ with `doom//reload-theme').") ;; Modeline library ;; -(defvar doom--modeline-alist ()) +(defvar doom--modeline-fn-alist ()) +(defvar doom--modeline-var-alist ()) (defmacro def-modeline-segment! (name &rest body) "Defines a modeline segment and byte compiles it." (declare (indent defun) (doc-string 2)) - (let ((docstring (if (stringp (car body)) (pop body)))) - (if (and (symbolp (car body)) - (not (cdr body))) - `(map-put doom--modeline-alist ',name ',(car body)) - (let ((sym (intern (format "doom-modeline-segment--%s" name)))) - `(progn - (defun ,sym () - ,(or docstring (format "%s modeline segment" name)) - ,@body) - (map-put doom--modeline-alist ',name ',sym) - ,(unless (bound-and-true-p byte-compile-current-file) - `(let (byte-compile-warnings) - (byte-compile #',sym)))))))) + (let ((sym (intern (format "doom-modeline-segment--%s" name))) + (docstring (if (stringp (car body)) + (pop body) + (format "%s modeline segment" name)))) + (cond ((and (symbolp (car body)) + (not (cdr body))) + (map-put doom--modeline-var-alist name (car body)) + `(map-put doom--modeline-var-alist ',name ',(car body))) + (t + (map-put doom--modeline-fn-alist name sym) + `(progn + (fset ',sym (lambda () ,docstring ,@body)) + (map-put doom--modeline-fn-alist ',name ',sym) + ,(unless (bound-and-true-p byte-compile-current-file) + `(let (byte-compile-warnings) + (byte-compile #',sym)))))))) (defsubst doom--prepare-modeline-segments (segments) (let (forms it) (dolist (seg segments) (cond ((stringp seg) (push seg forms)) - ((setq it (cdr (assq seg doom--modeline-alist))) - (push (cond ((boundp it) it) - ((fboundp it) (list it)) - ((error "%s is not a valid segment" seg))) - forms)) - ((fboundp seg) (push (list seg) forms)) + ((symbolp seg) + (cond ((setq it (cdr (assq seg doom--modeline-fn-alist))) + (push (list it) forms)) + ((setq it (cdr (assq seg doom--modeline-var-alist))) + (push it forms)) + ((error "%s is not a defined segment" seg)))) ((error "%s is not a valid segment" seg)))) (nreverse forms))) @@ -158,17 +162,21 @@ Example: (lhs-forms (doom--prepare-modeline-segments lhs)) (rhs-forms (doom--prepare-modeline-segments rhs))) `(progn - (defun ,sym () - ,(concat "Modeline:\n" (format " %s\n %s" lhs rhs)) - (let ((lhs (list ,@lhs-forms)) - (rhs (list ,@rhs-forms))) - (let ((rhs-str (format-mode-line rhs))) - (list lhs - (propertize - " " 'display - `((space :align-to (- (+ right right-fringe right-margin) - ,(+ 1 (string-width rhs-str)))))) - rhs-str)))) + (fset ',sym + (lambda () + ,(concat "Modeline:\n" + (format " %s\n %s" + (prin1-to-string lhs) + (prin1-to-string rhs))) + (let ((lhs (list ,@lhs-forms)) + (rhs (list ,@rhs-forms))) + (let ((rhs-str (format-mode-line rhs))) + (list lhs + (propertize + " " 'display + `((space :align-to (- (+ right right-fringe right-margin) + ,(+ 1 (string-width rhs-str)))))) + rhs-str))))) ,(unless (bound-and-true-p byte-compile-current-file) `(let (byte-compile-warnings) (byte-compile #',sym)))))) diff --git a/modules/ui/doom-modeline/config.el b/modules/ui/doom-modeline/config.el index 9754180f6..61e7a2f7b 100644 --- a/modules/ui/doom-modeline/config.el +++ b/modules/ui/doom-modeline/config.el @@ -372,7 +372,7 @@ directory, the file name, and its state (modified, read-only or non-existent)." ;; vcs ;; -(defvar +doom-modeline--vcs nil) +(defvar-local +doom-modeline--vcs nil) (defun +doom-modeline--update-vcs () (setq +doom-modeline--vcs (when (and vc-mode buffer-file-name) @@ -410,8 +410,9 @@ directory, the file name, and its state (modified, read-only or non-existent)." (add-hook 'after-save-hook #'+doom-modeline--update-vcs) (add-hook 'find-file-hook #'+doom-modeline--update-vcs t) -(def-modeline-var! vcs +doom-modeline--vcs - "Displays the current branch, colored based on its state.") +(def-modeline-segment! vcs + "Displays the current branch, colored based on its state." + +doom-modeline--vcs) ;; @@ -453,9 +454,10 @@ directory, the file name, and its state (modified, read-only or non-existent)." ('errored (+doom-ml-icon "sim_card_alert" "Error" 'doom-modeline-urgent)) ('interrupted (+doom-ml-icon "pause" "Interrupted" 'font-lock-doc-face))))) -(def-modeline-var! flycheck +doom-modeline--flycheck +(def-modeline-segment! flycheck "Displays color-coded flycheck error status in the current buffer with pretty -icons.") +icons." + +doom-modeline--flycheck) ;;