-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpath-headerline-mode.el
122 lines (113 loc) · 4.26 KB
/
path-headerline-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
;;; path-headerline-mode.el --- Displaying file path on headerline.
;;
;; Filename: path-headerline-mode.el
;; Description: Displaying file path on headerline.
;; Author: 7696122
;; Maintainer: 7696122
;; Created: Sat Sep 8 11:44:11 2012 (+0900)
;; Version: 0.0.2
;; Last-Updated: Wed Apr 23 22:32:03 2014 (+0900)
;; By: 7696122
;; Update #: 47
;; URL: https://github.com/7696122/path-headerline-mode
;; Keywords: headerline
;; Compatibility:
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; `Path headerline mode' is mode for displaying file path on headerline.
;; Modeline is too short to show filepath when split window by vertical.
;; path-headerline-mode show full file path if window width is enough.
;; but if window width is too short to show full file path, show directory path exclude file name.
;;
;;; Installation
;; Make sure "path-headerline-mode.el" is in your load path, then place
;; this code in your .emacs file:
;;
;; (require 'path-headerline-mode)
;; (path-headerline-mode +1)
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change Log:
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 3, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
(defmacro ph--with-face (str &rest properties)
`(propertize ,str 'face (list ,@properties)))
(defun ph--make-header ()
""
(let* ((ph--full-header (abbreviate-file-name buffer-file-name))
(ph--header (file-name-directory ph--full-header))
(ph--drop-str "[...]"))
(if (> (length ph--full-header)
(window-body-width))
(if (> (length ph--header)
(window-body-width))
(progn
(concat (ph--with-face ph--drop-str
:background "blue"
:weight 'bold)
(ph--with-face (substring ph--header
(+ (- (length ph--header)
(window-body-width))
(length ph--drop-str))
(length ph--header))
:weight 'bold)))
(concat (ph--with-face ph--header
:foreground "#8fb28f"
:weight 'bold)))
(concat (ph--with-face ph--header
:weight 'bold
:foreground "#8fb28f")
(ph--with-face (file-name-nondirectory buffer-file-name)
:weight 'bold)))))
(defun ph--display-header ()
"Display path on headerline."
(setq header-line-format
'("" ;; invocation-name
(:eval (if (buffer-file-name)
(ph--make-header)
"%b")))))
(defun path-header-line-on ()
"Display path on headerline for current buffer."
(interactive)
(ph--display-header))
(defun path-header-line-off ()
"Undisplay path on headerline for current buffer."
(interactive)
(setq header-line-format nil))
;;;###autoload
(define-minor-mode path-headerline-mode
"Displaying file path on headerline."
:global t
:group 'path-headerline-mode
(if path-headerline-mode
(progn
(add-hook 'buffer-list-update-hook #'ph--display-header))
(remove-hook 'buffer-list-update-hook #'ph--display-header)))
(provide 'path-headerline-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; path-headerline-mode.el ends here