From 28d11fd0e8db7fb7456ebd285174822b2056e645 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 20 Apr 2022 10:44:51 -0500 Subject: bleh --- lisp/+ace-window.el | 17 ++++--- lisp/+modeline.el | 142 +++++++++++++++++++++++++++++++++++++--------------- lisp/+org.el | 1 + lisp/+setup.el | 2 +- lisp/+tab-bar.el | 19 +++++-- 5 files changed, 130 insertions(+), 51 deletions(-) (limited to 'lisp') diff --git a/lisp/+ace-window.el b/lisp/+ace-window.el index fca27d9..9e631a2 100644 --- a/lisp/+ace-window.el +++ b/lisp/+ace-window.el @@ -10,15 +10,21 @@ ;; This is stolen from ace-window.el but with the mode-line stuff ripped out. :global t (if +ace-window-display-mode - (progn + (progn ; Enable (aw-update) (force-mode-line-update t) (add-hook 'window-configuration-change-hook 'aw-update) (add-hook 'after-make-frame-functions 'aw--after-make-frame t) (advice-add 'aw--lead-overlay :override 'ignore)) - (remove-hook 'window-configuration-change-hook 'aw-update) - (remove-hook 'after-make-frame-functions 'aw--after-make-frame) - (advice-remove 'aw--lead-overlay 'ignore))) + (progn ; Disable + (remove-hook 'window-configuration-change-hook 'aw-update) + (remove-hook 'after-make-frame-functions 'aw--after-make-frame) + (advice-remove 'aw--lead-overlay 'ignore)))) + +;; (defun +ace-window--mode-line-hint (path leaf) +;; (let ((wnd (cdr leaf))) +;; (with-selected-window wnd +;; ()))) ;;;###autoload (defun +ace-window-or-switch-buffer (arg) @@ -30,8 +36,5 @@ Switch to most recent buffer otherwise." (switch-to-buffer nil) (ace-window arg))) -(defun +ace-window@disable-overlay (_fn &rest _args) - "ADVICE for FN `aw--lead-overlay' (and ARGS) to not show overlays.") - (provide '+ace-window) ;;; +ace-window.el ends here diff --git a/lisp/+modeline.el b/lisp/+modeline.el index 3cc8806..3a922e3 100644 --- a/lisp/+modeline.el +++ b/lisp/+modeline.el @@ -32,7 +32,7 @@ functions), though it can also contain cons cells of the form (SEGMENT . PREDICATE). Segments are separated from each other using SEPARATOR, which -defaults to a \" \". space. Only segments that evaluate to a +defaults to a \" \". Only segments that evaluate to a non-trivial string (that is, a string not equal to \"\") will be separated, for a cleaner look. @@ -42,18 +42,18 @@ This function makes a lambda, so you can throw it straight into (lambda () (apply #'concat (let (this-sep result-list) - (dolist (segment segments) - (push (funcall (or (car-safe segment) segment) - this-sep) - result-list) - (if (or (cdr-safe segment) - (and (car result-list) - (not (equal (car result-list) "")))) - (setq this-sep separator) - (setq this-sep nil))) - (unless (seq-some #'null result-list) - (push +modeline-default-spacer result-list)) - (nreverse result-list))))) + (dolist (segment segments) + (push (funcall (or (car-safe segment) segment) + this-sep) + result-list) + (if (or (cdr-safe segment) + (and (car result-list) + (not (equal (car result-list) "")))) + (setq this-sep separator) + (setq this-sep nil))) + (unless (seq-some #'null result-list) + (push +modeline-default-spacer result-list)) + (nreverse result-list))))) ;;; Modeline segments @@ -62,14 +62,36 @@ This function makes a lambda, so you can throw it straight into (when string (string-replace "%" "%%" string))) +(defcustom +modeline-buffer-name-max-length 0 + "Maximum length of `+modeline-buffer-name'. +If > 0 and < 1, use that portion of the window's width. If > 1, +use that many characters. If anything else, don't limit. If the +buffer name is longer than the max length, it will be shortened +and appended with `truncate-string-ellipsis'." + :type '(choice (const :tag "No maximum length" 0) + (natnum :tag "Number of characters") + (float :tag "Fraction of window's width"))) + (defun +modeline-buffer-name (&optional spacer) ; gonsie "Display the buffer name." (let ((bufname (string-trim (string-replace "%" "" (buffer-name))))) (concat (or spacer +modeline-default-spacer) - (propertize bufname - 'help-echo (or (buffer-file-name) - (buffer-name)) - 'mouse-face 'mode-line-highlight)))) + (propertize (cond + ((ignore-errors + (and (> +modeline-buffer-name-max-length 0) + (< +modeline-buffer-name-max-length 1))) + (truncate-string-to-width bufname + (* (window-total-width) +modeline-buffer-name-max-length) + nil nil t)) + ((ignore-errors + (> +modeline-buffer-name-max-length 1)) + (truncate-string-to-width bufname + +modeline-buffer-name-max-length + nil nil t)) + (t bufname)) + 'help-echo (or (buffer-file-name) + (buffer-name)) + 'mouse-face 'mode-line-highlight)))) (defcustom +modeline-minions-icon "&" "The \"icon\" for `+modeline-minions' button." @@ -188,20 +210,49 @@ The order of elements matters: whichever one matches first is applied." "Toggle the percentage display in the mode line (File Percentage Mode)." :init-value t :global t :group 'mode-line) +(defun +modeline--percentage () + "Return point's progress through current file as a percentage." + (let ((tot (count-screen-lines (point-min) (point-max) :ignore-invisible))) + (floor (* 100 (/ (float (line-number-at-pos)) tot))))) + +(defun +modeline--buffer-contained-in-window-p () + "Whether the buffer is totally contained within its window." + (let ((window-min (save-excursion (move-to-window-line 0) (point))) + (window-max (save-excursion (move-to-window-line -1) (point)))) + (and (<= window-min (point-min)) + (>= window-max (point-max))))) + (defun +modeline-file-percentage (&optional spacer) "Display the position in the current file." (when file-percentage-mode - (let* ((tot (count-lines (point-min) (point-max) :ignore-invisible)) - (perc (/ (* 100 (line-number-at-pos)) tot)) - (window-min (save-excursion (move-to-window-line 0) - (point))) - (window-max (save-excursion (move-to-window-line -1) - (point)))) + ;; (let ((perc (+modeline--percentage))) + ;; (propertize (concat (or spacer +modeline-default-spacer) + ;; (cond + ;; ((+modeline--buffer-contained-in-window-p) "All") + ;; ((= (line-number-at-pos) (line-number-at-pos (point-min))) "Top") + ;; ((= (line-number-at-pos) (line-number-at-pos (point-max))) "Bot") + ;; ;; Why the 10 %s? Not sure. `format' knocks them + ;; ;; down to 5, then `format-mode-line' kills all but + ;; ;; two. If I use only 8, the margin is much too + ;; ;; large. Something else is obviously going on, but + ;; ;; I'm at a loss as to what it could be. + ;; (t (format "%d%%%%%%%%%%" perc)))) + ;; ;; TODO: add scroll-up and scroll-down bindings. + ;; )) + (let ((perc (format-mode-line '(-3 "%p")))) + (concat (or spacer +modeline-default-spacer) + perc + (unless (seq-some (lambda (s) (string= perc s)) + '("Top" "Bot" "All")) + "%%%%"))))) + +(defun +modeline-file-percentage-icon (&optional spacer) + "Display the position in the current file as an icon." + (when file-percentage-mode + (let ((perc (+modeline--percentage))) (propertize (concat (or spacer +modeline-default-spacer) (cond - ((and (<= window-min (point-min)) - (>= window-max (point-max))) - "█") + ((+modeline--buffer-contained-in-window-p) "⏹") ((= perc 0) "▇") ((< perc 20) "▆") ((< perc 40) "▅") @@ -231,24 +282,37 @@ The order of elements matters: whichever one matches first is applied." 'font-lock-face 'font-lock-variable-name-face)) "")) +(defun +modeline-line (&optional spacer) + (when line-number-mode + (concat (or spacer +modeline-default-spacer) "%2l"))) + +(defun +modeline-column (&optional spacer) + (when column-number-mode + (concat (or spacer +modeline-default-spacer) + (if column-number-indicator-zero-based "%2c" "%2C")))) + (defun +modeline-line-column (&optional spacer) ; adapted from `simple-modeline' "Display the current cursor line and column depending on modes." - (let ((sep "|") (before "") (after "") - (line-fmt (if line-number-mode "%2l" "")) - (col-fmt (if column-number-mode - (if column-number-indicator-zero-based - "%2c" - "%2C") - ""))) - (concat (or spacer +modeline-default-spacer) - before line-fmt sep col-fmt after))) + (funcall (+modeline-concat '(+modeline-line + +modeline-column) + "|"))) + +(defcustom +modeline-position-function nil + "Function to use instead of `+modeline-position' in modeline." + :type '(choice (const :tag "None" nil) + function) + :local t) (defun +modeline-position (&optional _) "Display the current cursor position. -See `line-number-mode', `column-number-mode', `file-percentage-mode'" - (append (+modeline-line-column) - (+modeline-region) - (+modeline-file-percentage))) +See `line-number-mode', `column-number-mode', and +`file-percentage-mode'. If `+modeline-position-function' is set +to a function in the current buffer, call that function instead." + (funcall (if +modeline-position-function + +modeline-position-function + (+modeline-concat '(+modeline-region + +modeline-line-column + +modeline-file-percentage))))) (defun +modeline-vc (&optional spacer) "Display the version control branch of the current buffer in the modeline." diff --git a/lisp/+org.el b/lisp/+org.el index 2a57fe2..e39bdc1 100644 --- a/lisp/+org.el +++ b/lisp/+org.el @@ -338,6 +338,7 @@ Return as a list." (save-mark-and-excursion (mark-whole-buffer) ;;(org-fill-paragraph nil t) + (+org-unsmartify) (+org-fix-blank-lines t) (org-align-tags t)))) diff --git a/lisp/+setup.el b/lisp/+setup.el index 7c658b6..02d2f09 100644 --- a/lisp/+setup.el +++ b/lisp/+setup.el @@ -35,7 +35,7 @@ Good for commenting.") (setup-define :face (lambda (face spec) - `(custom-set-faces '(,face ,spec 'now "Customized by `setup'."))) + `(custom-set-faces (list ,face ,spec 'now "Customized by `setup'."))) :documentation "Customize FACE with SPEC using `custom-set-faces'." :repeatable t) diff --git a/lisp/+tab-bar.el b/lisp/+tab-bar.el index 1f4745d..2c39dae 100644 --- a/lisp/+tab-bar.el +++ b/lisp/+tab-bar.el @@ -99,10 +99,10 @@ emms-player-playing-p) (let ((now-playing (+string-truncate (emms-mode-line-playlist-current) (- +tab-bar-emms-max-length 2)))) - `((emms-now-playing menu-item - ,(concat "{" now-playing "}" " ") - emms-pause - :help ,(emms-mode-line-playlist-current)))))) + `(emms-now-playing menu-item + ,(concat "{" now-playing "}" " ") + emms-pause + ( :help ,(emms-mode-line-playlist-current)))))) (defun +tab-bar-bongo () "Display Bongo now playing information." @@ -218,6 +218,17 @@ name to the left." (max 0 (- l-name tab-bar-tab-name-truncated-max l-ell)))) 'help-echo tab-name)))) +(defun +tab-bar-format-align-right () + "Align the rest of tab bar items to the right, pixel-wise." + ;; XXX: ideally, wouldn't require `shr' here + (require 'shr) ; `shr-string-pixel-width' + (let* ((rest (cdr (memq '+tab-bar-format-align-right tab-bar-format))) + (rest (tab-bar-format-list rest)) + (rest (mapconcat (lambda (item) (nth 2 item)) rest "")) + (hpos (shr-string-pixel-width rest)) + (str (propertize " " 'display `(space :align-to (- right (,hpos)))))) + `((align-right menu-item ,str ignore)))) + ;;; Menu bar ;; stole from https://github.com/emacs-mirror/emacs/blob/master/lisp/tab-bar.el -- cgit 1.4.1-21-gabe81