Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.7 KiB

4 years ago
  1. ;;; lv.el --- Other echo area
  2. ;; Package-Version: 20191106.1238
  3. ;; Copyright (C) 2015 Free Software Foundation, Inc.
  4. ;; Author: Oleh Krehel
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;
  18. ;; This package provides `lv-message' intended to be used in place of
  19. ;; `message' when semi-permanent hints are needed, in order to not
  20. ;; interfere with Echo Area.
  21. ;;
  22. ;; "Я тихо-тихо пiдглядаю,
  23. ;; І тiшуся собi, як бачу то,
  24. ;; Шо страшить i не пiдпускає,
  25. ;; А iншi п’ють тебе, як воду пiсок."
  26. ;; -- Андрій Кузьменко, L.V.
  27. ;;; Code:
  28. (defgroup lv nil
  29. "The other echo area."
  30. :group 'minibuffer
  31. :group 'hydra)
  32. (defcustom lv-use-separator nil
  33. "Whether to draw a line between the LV window and the Echo Area."
  34. :group 'lv
  35. :type 'boolean)
  36. (defcustom lv-use-padding nil
  37. "Whether to use horizontal padding in the LV window."
  38. :group 'lv
  39. :type 'boolean)
  40. (defface lv-separator
  41. '((((class color) (background light)) :background "grey80")
  42. (((class color) (background dark)) :background "grey30"))
  43. "Face used to draw line between the lv window and the echo area.
  44. This is only used if option `lv-use-separator' is non-nil.
  45. Only the background color is significant."
  46. :group 'lv)
  47. (defvar lv-wnd nil
  48. "Holds the current LV window.")
  49. (defvar display-line-numbers)
  50. (defvar display-fill-column-indicator)
  51. (defvar tab-line-format)
  52. (defun lv-window ()
  53. "Ensure that LV window is live and return it."
  54. (if (window-live-p lv-wnd)
  55. lv-wnd
  56. (let ((ori (selected-window))
  57. buf)
  58. (prog1 (setq lv-wnd
  59. (select-window
  60. (let ((ignore-window-parameters t))
  61. (split-window
  62. (frame-root-window) -1 'below))))
  63. (if (setq buf (get-buffer " *LV*"))
  64. (switch-to-buffer buf)
  65. (switch-to-buffer " *LV*")
  66. (set-window-hscroll lv-wnd 0)
  67. (setq window-size-fixed t)
  68. (setq mode-line-format nil)
  69. (setq header-line-format nil)
  70. (setq tab-line-format nil)
  71. (setq cursor-type nil)
  72. (setq display-line-numbers nil)
  73. (setq display-fill-column-indicator nil)
  74. (set-window-dedicated-p lv-wnd t)
  75. (set-window-parameter lv-wnd 'no-other-window t))
  76. (select-window ori)))))
  77. (defvar golden-ratio-mode)
  78. (defvar lv-force-update nil
  79. "When non-nil, `lv-message' will refresh even for the same string.")
  80. (defun lv--pad-to-center (str width)
  81. "Pad STR with spaces on the left to be centered to WIDTH."
  82. (let* ((strs (split-string str "\n"))
  83. (padding (make-string
  84. (/ (- width (length (car strs))) 2)
  85. ?\ )))
  86. (mapconcat (lambda (s) (concat padding s)) strs "\n")))
  87. (defun lv-message (format-string &rest args)
  88. "Set LV window contents to (`format' FORMAT-STRING ARGS)."
  89. (let* ((str (apply #'format format-string args))
  90. (n-lines (cl-count ?\n str))
  91. deactivate-mark
  92. golden-ratio-mode)
  93. (with-selected-window (lv-window)
  94. (when lv-use-padding
  95. (setq str (lv--pad-to-center str (window-width))))
  96. (unless (and (string= (buffer-string) str)
  97. (null lv-force-update))
  98. (delete-region (point-min) (point-max))
  99. (insert str)
  100. (when (and (window-system) lv-use-separator)
  101. (unless (looking-back "\n" nil)
  102. (insert "\n"))
  103. (insert
  104. (propertize "__" 'face 'lv-separator 'display '(space :height (1)))
  105. (propertize "\n" 'face 'lv-separator 'line-height t)))
  106. (set (make-local-variable 'window-min-height) n-lines)
  107. (setq truncate-lines (> n-lines 1))
  108. (let ((window-resize-pixelwise t)
  109. (window-size-fixed nil))
  110. (fit-window-to-buffer nil nil 1)))
  111. (goto-char (point-min)))))
  112. (defun lv-delete-window ()
  113. "Delete LV window and kill its buffer."
  114. (when (window-live-p lv-wnd)
  115. (let ((buf (window-buffer lv-wnd)))
  116. (delete-window lv-wnd)
  117. (kill-buffer buf))))
  118. (provide 'lv)
  119. ;;; lv.el ends here