diff options
-rw-r--r-- | dashboard.el | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/dashboard.el b/dashboard.el index 1abc53d..56bb616 100644 --- a/dashboard.el +++ b/dashboard.el @@ -1,5 +1,29 @@ ;;; dashboard.el --- My daashboard -*- lexical-binding: t; -*- +(defun dashboard-center-string (str) + "Return a centered string." + (let ((current-window-width (1- (window-width nil t))) + (str-width (string-pixel-width str))) + (cond + ((display-graphic-p) + (concat + (propertize + (string 32) + 'display + (list + 'space + :width + (list (floor (- current-window-width str-width) 2)))) + str)) + (t + (concat + (make-string + (round + (- current-window-width str-width) + (* 2 (string-pixel-width (string 32)))) + 32) + str))))) + ;;;###autoload (defvar dashboard-buffer-name "durand" "The name of the buffer for the dashboard.") @@ -42,37 +66,32 @@ If FORCE is non-nil, re-gerenate the dashboard buffer." (erase-buffer) (cond ((display-graphic-p) - (let* ((image - (create-image - (expand-file-name - "cat.png" - user-emacs-directory))) - (str (propertize - " " - 'display image - 'rear-nonsticky '(display))) - (str-width (string-pixel-width str))) + (let ((image + (create-image + (expand-file-name + "cat.png" + user-emacs-directory)))) (insert (make-string 3 10) - (propertize - (string 32) - 'display - (list - 'space - :width - (list (floor (- (window-body-width nil t) str-width) 2)))) - str))) + (dashboard-center-string + (propertize + " " + 'display image + 'rear-nonsticky '(display)))))) ((mapc (function (lambda (str) (insert - (center-string-in-width str (- (window-body-width) 13)) + (dashboard-center-string str) "\n"))) dashboard-cat-text))) (newline 5) - (insert (center-string-in-width "Dashboard" (window-body-width))) + (insert + (dashboard-center-string "Dashboard")) (set-buffer-modified-p nil) (read-only-mode 1) - (set 'mode-line-format '("%e" (:eval (modeline-format-dashboard)))) + (set + 'mode-line-format + '("%e" (:eval (modeline-format-dashboard)))) (set 'default-directory user-emacs-directory) (view-mode 1) (dashboard-mode)))) |