-
Notifications
You must be signed in to change notification settings - Fork 0
/
yawc-mode.el
138 lines (115 loc) · 4.08 KB
/
yawc-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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
;;; yawc-mode.el --- yet another wc-mode -*- lexical-binding: t; -*-
;; Copyright (C) 2016 ril
;; Author: ril
;; Created: 2016-01-16 12:00:00
;; Last Modified: 2022-07-07 21:52:50
;; Version: 1.1
;; Keywords: convenience, mode line
;; URL: https://github.com/fenril058/yawc-mode
;; 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 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; A simple minor-mode to display the length of the buffer in the mode
;; line. This is deeply based on the wc-mode which made by Toby
;; Cubitt. URL: http://www.dr-qubit.org/emacs.php
;;; Code:
(defgroup yawc nil
"Display the total number of characters, words, and lines in
the mode-line."
:group 'mode-line)
(defcustom yawc-mode-jp nil
"non-nilならば、`yawc-mode-line-format-jp' によってモード
ラインに表示します。デフォルトの形式は%d文字%d行です。文字数に改
行は含みません。"
:type 'boolean
:group 'yawc)
(make-variable-buffer-local 'yawc-mode-jp)
(defcustom yawc-use-disable-list nil
"If nil, global-yawc-mode enables yawc-mode in the modes which
are the member of `yawc-enable-modes'. If non-nil, global-yawc-mode
enables yawc-mode in all modes except in `yawc-disable-modes'. "
:type 'boolean
:group 'yawc)
(defcustom yawc-enable-modes '(org-mode)
"Major modes which `yawc-mode' can run on."
:type 'list
:group 'yawc)
(defcustom yawc-disable-modes '(lisp-interaction-mode)
"Major modes which `yawc-mode' can not run on."
:type 'list
:group 'yawc)
(defvar yawc-mode-line-format
'(if (use-region-p)
(format "%d,%d,%d"
(abs (- (point) (mark)))
(count-words-region (point) (mark))
(abs (+ (- (line-number-at-pos (point))
(line-number-at-pos (mark))) 1)))
(format "%d,%d,%d"
(point-max)
(count-words-region (point-min) (point-max))
(line-number-at-pos (point-max)))))
(defvar yawc-mode-line-format-jp
'(if (use-region-p)
(format "%d文字%d行"
(abs (- (point) (mark)))
(abs (+ (- (line-number-at-pos (point))
(line-number-at-pos (mark))) 1)))
(let* ((pmax (point-max))
(lnap (line-number-at-pos pmax)))
(format "%d文字%d行"
(- pmax lnap)
lnap
)))
)
(defvar yawc-mode-display-style
`(yawc-mode
(6 (:eval
(if yawc-mode-jp
,yawc-mode-line-format-jp
,yawc-mode-line-format
)))
nil)
)
(add-to-list 'mode-line-position yawc-mode-display-style t)
(defun yawc-mode-line-position-cleanup ()
(interactive)
(setq mode-line-position
(assq-delete-all 'yawc-mode mode-line-position))
)
(defun yawc-mode-line-position-set ()
(interactive)
(add-to-list 'mode-line-position 'yawc-mode t)
)
;;;###autoload
(define-minor-mode yawc-mode
"Minor-mode which display the total number of characters,
words, and lines in the mode-line. If you use region, those in
the region are displayed."
:group 'yawc
:init-value nil
:global nil
:lighter ""
)
(defun yawc-mode-maybe ()
"What buffer `yawc-mode' prefers."
(when (and (not (minibufferp (current-buffer)))
(if yawc-use-disable-list
(not (memq major-mode yawc-disable-modes))
(memq major-mode yawc-enable-modes))
(yawc-mode 1)
)))
;;;###autoload
(define-global-minor-mode global-yawc-mode
yawc-mode yawc-mode-maybe
:group 'yawc)
(provide 'yawc-mode)
;;; yawc-mode.el ends here