aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2002-11-02 06:13:57 +0000
committerStefan Monnier2002-11-02 06:13:57 +0000
commit18a9f9681592fac043c8f4781729d0aefff4e3fb (patch)
treea39ce6fd6dc20630b0be96a0eaf2322b313fbd8c
parent408784a7d589e1ccc6a04b7cf5f6e82e85e42ff0 (diff)
downloademacs-18a9f9681592fac043c8f4781729d0aefff4e3fb.tar.gz
emacs-18a9f9681592fac043c8f4781729d0aefff4e3fb.zip
(mode-line-change-eol, mode-line-eol-desc-cache, mode-line-eol-desc): New.
(mode-line-mule-info): Use them for the EOL part of the modeline.
-rw-r--r--lisp/bindings.el43
1 files changed, 38 insertions, 5 deletions
diff --git a/lisp/bindings.el b/lisp/bindings.el
index a9da9333f01..705d3d56058 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -135,6 +135,38 @@ corresponding to the mode line clicked."
135 "Local keymap for the coding-system part of the mode line.") 135 "Local keymap for the coding-system part of the mode line.")
136 136
137 137
138(defun mode-line-change-eol ()
139 "Cycle through the various possible kinds of end-of-line styles."
140 (interactive)
141 (let ((eol (coding-system-eol-type buffer-file-coding-system)))
142 (set-buffer-file-coding-system
143 (cond ((eq eol 0) 'dos) ((eq eol 1) 'mac) (t 'unix)))))
144
145(defvar mode-line-eol-desc-cache nil)
146
147(defun mode-line-eol-desc ()
148 (let* ((eol (coding-system-eol-type buffer-file-coding-system))
149 (mnemonic (coding-system-eol-type-mnemonic buffer-file-coding-system))
150 (desc (assq eol mode-line-eol-desc-cache)))
151 (if (and desc (eq (cadr desc) mnemonic))
152 (cddr desc)
153 (if desc (setq mode-line-eol-desc-cache nil)) ;Flush the cache if stale.
154 (setq desc
155 (propertize
156 mnemonic
157 'help-echo (format "%s end-of-line; mouse-3 to cycle"
158 (if (eq eol 0) "Unix-style LF"
159 (if (eq eol 1) "Dos-style CRLF"
160 (if (eq eol 2) "Mac-style CR"
161 "Undecided"))))
162 'keymap
163 (eval-when-compile
164 (let ((map (make-sparse-keymap)))
165 (define-key map [mode-line mouse-3] 'mode-line-change-eol)
166 map))))
167 (push (cons eol (cons mnemonic desc)) mode-line-eol-desc-cache)
168 desc)))
169
138(defvar mode-line-mule-info 170(defvar mode-line-mule-info
139 `("" 171 `(""
140 (current-input-method 172 (current-input-method
@@ -145,7 +177,7 @@ corresponding to the mode line clicked."
145 ". mouse-2: disable, mouse-3: describe") 177 ". mouse-2: disable, mouse-3: describe")
146 local-map ,mode-line-input-method-map)) 178 local-map ,mode-line-input-method-map))
147 ,(propertize 179 ,(propertize
148 "%Z" 180 "%z"
149 'help-echo 181 'help-echo
150 #'(lambda (window object point) 182 #'(lambda (window object point)
151 (with-current-buffer (window-buffer window) 183 (with-current-buffer (window-buffer window)
@@ -157,16 +189,17 @@ corresponding to the mode line clicked."
157 " buffer; mouse-3: describe coding system") 189 " buffer; mouse-3: describe coding system")
158 (concat "Unibyte " (symbol-name buffer-file-coding-system) 190 (concat "Unibyte " (symbol-name buffer-file-coding-system)
159 " buffer"))))) 191 " buffer")))))
160 'local-map mode-line-coding-system-map)) 192 'local-map mode-line-coding-system-map)
193 (:eval (mode-line-eol-desc)))
161 "Mode-line control for displaying information of multilingual environment. 194 "Mode-line control for displaying information of multilingual environment.
162Normally it displays current input method (if any activated) and 195Normally it displays current input method (if any activated) and
163mnemonics of the following coding systems: 196mnemonics of the following coding systems:
164 coding system for saving or writing the current buffer 197 coding system for saving or writing the current buffer
165 coding system for keyboard input (if Emacs is running on terminal) 198 coding system for keyboard input (if Emacs is running on terminal)
166 coding system for terminal output (if Emacs is running on terminal)" 199 coding system for terminal output (if Emacs is running on terminal)"
167;;; Currently not: 200 ;; Currently not:
168;;; coding system for decoding output of buffer process (if any) 201 ;; coding system for decoding output of buffer process (if any)
169;;; coding system for encoding text to send to buffer process (if any)." 202 ;; coding system for encoding text to send to buffer process (if any)."
170) 203)
171 204
172(make-variable-buffer-local 'mode-line-mule-info) 205(make-variable-buffer-local 'mode-line-mule-info)