Personal emacs config
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.

122 lines
4.0 KiB

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