al-mode-line.el 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ;;; al-mode-line.el --- Additional functionality for mode-line
  2. ;; Copyright © 2014-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. ;;; Mode names
  15. ;; Idea from
  16. ;; <http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/>.
  17. (defvar al/mode-names-alist nil
  18. "Alist of mode names.
  19. Car of each assoc is a `major-mode'. Cdr is a string or a
  20. function returning a string used for `mode-name'.")
  21. ;;;###autoload
  22. (defun al/mode-name (&rest _)
  23. "Replace `mode-name' of the current major mode.
  24. Use the appropriate name from `al/mode-names-alist'.
  25. This function is intended to be used in `after-change-major-mode-hook'."
  26. (interactive)
  27. (let ((name (cdr (assq major-mode al/mode-names-alist))))
  28. (when name
  29. (setq mode-name
  30. (if (functionp name) (funcall name) name)))))
  31. ;;;###autoload
  32. (defun al/mode-line-default-buffer-identification (mode)
  33. "Set `mode-line-buffer-identification' to the default value for MODE.
  34. Some major modes like to override
  35. `mode-line-buffer-identification'. If you want to force a mode
  36. to use the default value, call this function like this:
  37. (al/mode-line-default-buffer-identification 'Man-mode)
  38. (al/mode-line-default-buffer-identification 'dired-mode)"
  39. (let ((hook (intern (concat (symbol-name mode) "-hook"))))
  40. (add-hook hook
  41. (lambda ()
  42. (setq mode-line-buffer-identification
  43. (default-value 'mode-line-buffer-identification))))))
  44. ;;; Mode line process
  45. (defvar al/mode-line-process '("[%s]")
  46. "String used in `al/mode-line-process' function.")
  47. ;;;###autoload
  48. (defun al/mode-line-process ()
  49. "Set `mode-line-process' to the value of `al/mode-line-process'.
  50. This function is intended to be used in hooks:
  51. (add-hook 'comint-mode-hook 'al/mode-line-process)"
  52. (setq mode-line-process al/mode-line-process))
  53. ;;; Additional info for major modes
  54. ;; To see some additional info in the mode line, I add `al/mode-info'
  55. ;; to the `mode-line-modes'.
  56. (defvar-local al/mode-info nil
  57. "Part of mode line with additional info for the current major mode.")
  58. (put 'al/mode-info 'risky-local-variable t)
  59. ;;;###autoload
  60. (defun al/mode-ibuffer-info ()
  61. "Set `al/mode-info' to the additional info for `ibuffer-mode'.
  62. This function is intended to be added to `ibuffer-mode-hook'."
  63. (setq al/mode-info
  64. '(""
  65. (ibuffer-sorting-mode (:eval (symbol-name ibuffer-sorting-mode)))
  66. (ibuffer-sorting-reversep "|r"))))
  67. (provide 'al-mode-line)
  68. ;;; al-mode-line.el ends here