changeset 48124:110ec10bd1ea

(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.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 02 Nov 2002 06:13:57 +0000
parents 66755860a8f1
children d43e830821e0
files lisp/bindings.el
diffstat 1 files changed, 38 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/bindings.el	Sat Nov 02 05:29:13 2002 +0000
+++ b/lisp/bindings.el	Sat Nov 02 06:13:57 2002 +0000
@@ -135,6 +135,38 @@
   "Local keymap for the coding-system part of the mode line.")
 
 
+(defun mode-line-change-eol ()
+  "Cycle through the various possible kinds of end-of-line styles."
+  (interactive)
+  (let ((eol (coding-system-eol-type buffer-file-coding-system)))
+    (set-buffer-file-coding-system
+     (cond ((eq eol 0) 'dos) ((eq eol 1) 'mac) (t 'unix)))))
+
+(defvar mode-line-eol-desc-cache nil)
+
+(defun mode-line-eol-desc ()
+  (let* ((eol (coding-system-eol-type buffer-file-coding-system))
+	 (mnemonic (coding-system-eol-type-mnemonic buffer-file-coding-system))
+	 (desc (assq eol mode-line-eol-desc-cache)))
+    (if (and desc (eq (cadr desc) mnemonic))
+	(cddr desc)
+      (if desc (setq mode-line-eol-desc-cache nil)) ;Flush the cache if stale.
+      (setq desc
+	    (propertize
+	     mnemonic
+	     'help-echo (format "%s end-of-line; mouse-3 to cycle"
+				(if (eq eol 0) "Unix-style LF"
+				  (if (eq eol 1) "Dos-style CRLF"
+				    (if (eq eol 2) "Mac-style CR"
+				      "Undecided"))))
+	     'keymap
+	     (eval-when-compile
+	       (let ((map (make-sparse-keymap)))
+		 (define-key map [mode-line mouse-3] 'mode-line-change-eol)
+		 map))))
+      (push (cons eol (cons mnemonic desc)) mode-line-eol-desc-cache)
+      desc)))
+
 (defvar mode-line-mule-info
   `(""
     (current-input-method
@@ -145,7 +177,7 @@
 			     ".  mouse-2: disable, mouse-3: describe")
 		  local-map ,mode-line-input-method-map))
     ,(propertize
-      "%Z"
+      "%z"
       'help-echo
       #'(lambda (window object point)
 	  (with-current-buffer (window-buffer window)
@@ -157,16 +189,17 @@
 			  " buffer; mouse-3: describe coding system")
 		(concat "Unibyte " (symbol-name buffer-file-coding-system)
 			" buffer")))))
-      'local-map mode-line-coding-system-map))
+      'local-map mode-line-coding-system-map)
+    (:eval (mode-line-eol-desc)))
   "Mode-line control for displaying information of multilingual environment.
 Normally it displays current input method (if any activated) and
 mnemonics of the following coding systems:
   coding system for saving or writing the current buffer
   coding system for keyboard input (if Emacs is running on terminal)
   coding system for terminal output (if Emacs is running on terminal)"
-;;; Currently not:
-;;;  coding system for decoding output of buffer process (if any)
-;;;  coding system for encoding text to send to buffer process (if any)."
+  ;; Currently not:
+  ;;  coding system for decoding output of buffer process (if any)
+  ;;  coding system for encoding text to send to buffer process (if any)."
 )
 
 (make-variable-buffer-local 'mode-line-mule-info)