aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasatake YAMATO2004-03-15 07:27:02 +0000
committerMasatake YAMATO2004-03-15 07:27:02 +0000
commit9fd76d04e8b93bb6116dffe49b8fdabdac71286f (patch)
treefe6d8918286e794fb0f8cd66991abf78f3c4f180
parent6e54fa536d7848031898ae11a228d40ca2c81a61 (diff)
downloademacs-9fd76d04e8b93bb6116dffe49b8fdabdac71286f.tar.gz
emacs-9fd76d04e8b93bb6116dffe49b8fdabdac71286f.zip
2004-03-15 Masatake YAMATO <jet@gyve.org>
* hl-line.el (hl-line-range-function): New variable. (hl-line-move): New function. (global-hl-line-highlight): Use `hl-line-move'. (hl-line-highlight): Ditto. * scroll-bar.el (scroll-bar-columns): New function derived from ruler-mode.el. * fringe.el (fringe-columns): New function derived from ruler-mode.el. * ruler-mode.el (top-level): Require scroll-bar and fringe. (ruler-mode-left-fringe-cols) (ruler-mode-right-fringe-cols): Use `fringe-columns'. (ruler-mode-right-scroll-bar-cols) (ruler-mode-left-scroll-bar-cols): Use `scroll-bar-columns'. (ruler-mode-ruler-function): New variable. (ruler-mode-header-line-format): Call `ruler-mode-ruler-function' if the value for `ruler-mode-ruler-function'is given. * hexl.el (hexl-mode-hook): Make the hook customizable. (hexl-address-area, hexl-ascii-area, hexl-ascii-cursor): New customize variables. (hexlify-buffer): Put font-lock-faces on the address area and the ascii area. (hexl-activate-ruler): New function. (hexl-follow-line): New function. (hexl-highlight-line-range): New function. (hexl-mode-ruler): New function.
-rw-r--r--lisp/ChangeLog32
-rw-r--r--lisp/fringe.el11
-rw-r--r--lisp/hexl.el82
-rw-r--r--lisp/hl-line.el36
-rw-r--r--lisp/ruler-mode.el46
-rw-r--r--lisp/scroll-bar.el17
6 files changed, 193 insertions, 31 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index fe1b7db508e..b28512af321 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,35 @@
12004-03-15 Masatake YAMATO <jet@gyve.org>
2
3 * hl-line.el (hl-line-range-function): New variable.
4 (hl-line-move): New function.
5 (global-hl-line-highlight): Use `hl-line-move'.
6 (hl-line-highlight): Ditto.
7
8 * scroll-bar.el (scroll-bar-columns): New function derived from
9 ruler-mode.el.
10
11 * fringe.el (fringe-columns): New function derived from
12 ruler-mode.el.
13
14 * ruler-mode.el (top-level): Require scroll-bar and fringe.
15 (ruler-mode-left-fringe-cols)
16 (ruler-mode-right-fringe-cols): Use `fringe-columns'.
17 (ruler-mode-right-scroll-bar-cols)
18 (ruler-mode-left-scroll-bar-cols): Use `scroll-bar-columns'.
19 (ruler-mode-ruler-function): New variable.
20 (ruler-mode-header-line-format): Call `ruler-mode-ruler-function'
21 if the value for `ruler-mode-ruler-function'is given.
22
23 * hexl.el (hexl-mode-hook): Make the hook customizable.
24 (hexl-address-area, hexl-ascii-area, hexl-ascii-cursor): New
25 customize variables.
26 (hexlify-buffer): Put font-lock-faces on the address area and
27 the ascii area.
28 (hexl-activate-ruler): New function.
29 (hexl-follow-line): New function.
30 (hexl-highlight-line-range): New function.
31 (hexl-mode-ruler): New function.
32
12004-03-12 Jesper Harder <harder@ifa.au.dk> 332004-03-12 Jesper Harder <harder@ifa.au.dk>
2 34
3 * info-look.el (info-lookup): Reuse an existing Info window. 35 * info-look.el (info-lookup): Reuse an existing Info window.
diff --git a/lisp/fringe.el b/lisp/fringe.el
index ab7709332f5..f52ecdf64d2 100644
--- a/lisp/fringe.el
+++ b/lisp/fringe.el
@@ -218,6 +218,17 @@ default appearance of fringes on all frames, see the command
218 (list (cons 'left-fringe (if (consp mode) (car mode) mode)) 218 (list (cons 'left-fringe (if (consp mode) (car mode) mode))
219 (cons 'right-fringe (if (consp mode) (cdr mode) mode))))) 219 (cons 'right-fringe (if (consp mode) (cdr mode) mode)))))
220 220
221(defsubst fringe-columns (side &optional real)
222 "Return the width, measured in columns, of the fringe area on SIDE.
223If optional argument REAL is non-nil, return a real floating point
224number instead of a rounded integer value.
225SIDE must be the symbol `left' or `right'."
226 (funcall (if real '/ 'ceiling)
227 (or (funcall (if (eq side 'left) 'car 'cadr)
228 (window-fringes))
229 0)
230 (float (frame-char-width))))
231
221(provide 'fringe) 232(provide 'fringe)
222 233
223;;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d 234;;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d
diff --git a/lisp/hexl.el b/lisp/hexl.el
index 9fd21824f26..66aceeaee71 100644
--- a/lisp/hexl.el
+++ b/lisp/hexl.el
@@ -78,6 +78,22 @@ Quoting cannot be used, so the arguments cannot themselves contain spaces."
78 :group 'hexl 78 :group 'hexl
79 :version "20.3") 79 :version "20.3")
80 80
81(defcustom hexl-mode-hook '(hexl-follow-line hexl-activate-ruler)
82 "Normal hook run when entering Hexl mode."
83 :type 'hook
84 :options '(hexl-follow-line hexl-activate-ruler turn-on-eldoc-mode)
85 :group 'hexl)
86
87(defface hexl-address-area
88 '((t (:inherit header-line)))
89 "Face used in address are of hexl-mode buffer."
90 :group 'hexl)
91
92(defface hexl-ascii-area
93 '((t (:inherit header-line)))
94 "Face used in ascii are of hexl-mode buffer."
95 :group 'hexl)
96
81(defvar hexl-max-address 0 97(defvar hexl-max-address 0
82 "Maximum offset into hexl buffer.") 98 "Maximum offset into hexl buffer.")
83 99
@@ -648,6 +664,15 @@ This discards the buffer's undo information."
648 (apply 'call-process-region (point-min) (point-max) 664 (apply 'call-process-region (point-min) (point-max)
649 (expand-file-name hexl-program exec-directory) 665 (expand-file-name hexl-program exec-directory)
650 t t nil (split-string hexl-options)) 666 t t nil (split-string hexl-options))
667 (save-excursion
668 (goto-char (point-min))
669 (while (re-search-forward "^[0-9a-f]+:" nil t)
670 (put-text-property (match-beginning 0) (match-end 0)
671 'font-lock-face 'hexl-address-area))
672 (goto-char (point-min))
673 (while (re-search-forward " \\(.+$\\)" nil t)
674 (put-text-property (match-beginning 1) (match-end 1)
675 'font-lock-face 'hexl-ascii-area)))
651 (if (> (point) (hexl-address-to-marker hexl-max-address)) 676 (if (> (point) (hexl-address-to-marker hexl-max-address))
652 (hexl-goto-address hexl-max-address)))) 677 (hexl-goto-address hexl-max-address))))
653 678
@@ -865,6 +890,32 @@ Customize the variable `hexl-follow-ascii' to disable this feature."
865 (remove-hook 'post-command-hook 'hexl-follow-ascii-find t) 890 (remove-hook 'post-command-hook 'hexl-follow-ascii-find t)
866 ))))) 891 )))))
867 892
893(defun hexl-activate-ruler ()
894 "Activate `ruler-mode'"
895 (require 'ruler-mode)
896 (set (make-local-variable 'ruler-mode-ruler-function)
897 'hexl-mode-ruler)
898 (ruler-mode 1))
899
900(defun hexl-follow-line ()
901 "Activate `hl-line-mode'"
902 (require 'frame)
903 (require 'fringe)
904 (require 'hl-line)
905 (set (make-local-variable 'hl-line-range-function)
906 'hexl-highlight-line-range)
907 (set (make-local-variable 'hl-line-face)
908 'highlight)
909 (hl-line-mode 1))
910
911(defun hexl-highlight-line-range ()
912 "Return the range of address area for the point.
913This function is assumed to be used as call back function for `hl-line-mode'."
914 (cons
915 (line-beginning-position)
916 ;; 9 stands for (length "87654321:")
917 (+ (line-beginning-position) 9)))
918
868(defun hexl-follow-ascii-find () 919(defun hexl-follow-ascii-find ()
869 "Find and highlight the ASCII element corresponding to current point." 920 "Find and highlight the ASCII element corresponding to current point."
870 (let ((pos (+ 51 921 (let ((pos (+ 51
@@ -873,6 +924,37 @@ Customize the variable `hexl-follow-ascii' to disable this feature."
873 (move-overlay hexl-ascii-overlay pos (1+ pos)) 924 (move-overlay hexl-ascii-overlay pos (1+ pos))
874 )) 925 ))
875 926
927(defun hexl-mode-ruler ()
928 "Return a string ruler for hexl mode."
929 (let* ((highlight (mod (hexl-current-address) 16))
930 (s "87654321 0011 2233 4455 6677 8899 aabb ccdd eeff 0123456789abcdef")
931 (pos 0)
932 (spaces (+ (scroll-bar-columns 'left)
933 (fringe-columns 'left)
934 (or (car (window-margins)) 0))))
935 (set-text-properties 0 (length s) nil s)
936 ;; Turn spaces in the header into stretch specs so they work
937 ;; regardless of the header-line face.
938 (while (string-match "[ \t]+" s pos)
939 (setq pos (match-end 0))
940 (put-text-property (match-beginning 0) pos 'display
941 ;; Assume fixed-size chars
942 `(space :align-to (+ (scroll-bar . left)
943 left-fringe left-margin
944 ,pos))
945 s))
946 ;; Highlight the current column.
947 (put-text-property (+ 10 (/ (* 5 highlight) 2))
948 (+ 12 (/ (* 5 highlight) 2))
949 'face 'highlight s)
950 ;; Highlight the current ascii column
951 (put-text-property (+ 12 39 highlight) (+ 12 40 highlight)
952 'face 'highlight s)
953 ;; Add the leading space.
954 (concat (propertize (make-string (floor spaces) ? )
955 'display `(space :width ,spaces))
956 s)))
957
876;; startup stuff. 958;; startup stuff.
877 959
878(if hexl-mode-map 960(if hexl-mode-map
diff --git a/lisp/hl-line.el b/lisp/hl-line.el
index 58921aaa58a..5ed334f4049 100644
--- a/lisp/hl-line.el
+++ b/lisp/hl-line.el
@@ -57,6 +57,10 @@
57;; it to nil to avoid highlighting specific buffers, when the global 57;; it to nil to avoid highlighting specific buffers, when the global
58;; mode is used. 58;; mode is used.
59 59
60;; In default whole the line is highlighted. The range of highlighting
61;; can be changed by defining an appropriate function as the
62;; buffer-local value of `hl-line-range-function'.
63
60;;; Code: 64;;; Code:
61 65
62(defgroup hl-line nil 66(defgroup hl-line nil
@@ -78,6 +82,15 @@ the command `hl-line-mode' to turn Hl-Line mode on."
78 :version "21.4" 82 :version "21.4"
79 :group 'hl-line) 83 :group 'hl-line)
80 84
85(defvar hl-line-range-function nil
86 "If non-nil, function to call to return highlight range.
87The function of no args should return a cons cell; its car value
88is the beginning position of highlight and its cdr value is the
89end position of highlight in the buffer.
90It should return nil if there's no region to be highlighted.
91
92This variable is expected to be made buffer-local by modes.")
93
81(defvar hl-line-overlay nil 94(defvar hl-line-overlay nil
82 "Overlay used by Hl-Line mode to highlight the current line.") 95 "Overlay used by Hl-Line mode to highlight the current line.")
83(make-variable-buffer-local 'hl-line-overlay) 96(make-variable-buffer-local 'hl-line-overlay)
@@ -124,8 +137,7 @@ addition to `hl-line-highlight' on `post-command-hook'."
124 (overlay-put hl-line-overlay 'face hl-line-face)) 137 (overlay-put hl-line-overlay 'face hl-line-face))
125 (overlay-put hl-line-overlay 138 (overlay-put hl-line-overlay
126 'window (unless hl-line-sticky-flag (selected-window))) 139 'window (unless hl-line-sticky-flag (selected-window)))
127 (move-overlay hl-line-overlay 140 (hl-line-move hl-line-overlay))
128 (line-beginning-position) (line-beginning-position 2)))
129 (hl-line-unhighlight))) 141 (hl-line-unhighlight)))
130 142
131(defun hl-line-unhighlight () 143(defun hl-line-unhighlight ()
@@ -158,14 +170,30 @@ Global-Hl-Line mode uses the functions `global-hl-line-unhighlight' and
158 (setq global-hl-line-overlay (make-overlay 1 1)) ; to be moved 170 (setq global-hl-line-overlay (make-overlay 1 1)) ; to be moved
159 (overlay-put global-hl-line-overlay 'face hl-line-face)) 171 (overlay-put global-hl-line-overlay 'face hl-line-face))
160 (overlay-put global-hl-line-overlay 'window (selected-window)) 172 (overlay-put global-hl-line-overlay 'window (selected-window))
161 (move-overlay global-hl-line-overlay 173 (hl-line-move global-hl-line-overlay))))
162 (line-beginning-position) (line-beginning-position 2)))))
163 174
164(defun global-hl-line-unhighlight () 175(defun global-hl-line-unhighlight ()
165 "Deactivate the Global-Hl-Line overlay on the current line." 176 "Deactivate the Global-Hl-Line overlay on the current line."
166 (if global-hl-line-overlay 177 (if global-hl-line-overlay
167 (delete-overlay global-hl-line-overlay))) 178 (delete-overlay global-hl-line-overlay)))
168 179
180(defun hl-line-move (overlay)
181 "Move the hl-line-mode overlay.
182If `hl-line-range-function' is non-nil, move the OVERLAY to the position
183where the function returns. If `hl-line-range-function' is nil, fill
184the line including the point by OVERLAY."
185 (let (tmp b e)
186 (if hl-line-range-function
187 (setq tmp (funcall hl-line-range-function)
188 b (car tmp)
189 e (cdr tmp))
190 (setq tmp t
191 b (line-beginning-position)
192 e (line-beginning-position 2)))
193 (if tmp
194 (move-overlay overlay b e)
195 (move-overlay overlay 1 1))))
196
169(provide 'hl-line) 197(provide 'hl-line)
170 198
171;;; arch-tag: ac806940-0876-4959-8c89-947563ee2833 199;;; arch-tag: ac806940-0876-4959-8c89-947563ee2833
diff --git a/lisp/ruler-mode.el b/lisp/ruler-mode.el
index 18fdcddd507..d6c205a23b4 100644
--- a/lisp/ruler-mode.el
+++ b/lisp/ruler-mode.el
@@ -94,6 +94,9 @@
94;; WARNING: To keep ruler graduations aligned on text columns it is 94;; WARNING: To keep ruler graduations aligned on text columns it is
95;; important to use the same font family and size for ruler and text 95;; important to use the same font family and size for ruler and text
96;; areas. 96;; areas.
97;;
98;; You can override the ruler format by defining an appropriate
99;; function as the buffer-local value of `ruler-mode-ruler-function'.
97 100
98;; Installation 101;; Installation
99;; 102;;
@@ -108,6 +111,8 @@
108;;; Code: 111;;; Code:
109(eval-when-compile 112(eval-when-compile
110 (require 'wid-edit)) 113 (require 'wid-edit))
114(require 'scroll-bar)
115(require 'fringe)
111 116
112(defgroup ruler-mode nil 117(defgroup ruler-mode nil
113 "Display a ruler in the header line." 118 "Display a ruler in the header line."
@@ -298,42 +303,21 @@ or remove a tab stop. \\[ruler-mode-toggle-show-tab-stops] or
298 "Return the width, measured in columns, of the left fringe area. 303 "Return the width, measured in columns, of the left fringe area.
299If optional argument REAL is non-nil, return a real floating point 304If optional argument REAL is non-nil, return a real floating point
300number instead of a rounded integer value." 305number instead of a rounded integer value."
301 (funcall (if real '/ 'ceiling) 306 (fringe-columns 'left real))
302 (or (car (window-fringes)) 0)
303 (float (frame-char-width))))
304 307
305(defsubst ruler-mode-right-fringe-cols (&optional real) 308(defsubst ruler-mode-right-fringe-cols (&optional real)
306 "Return the width, measured in columns, of the right fringe area. 309 "Return the width, measured in columns, of the right fringe area.
307If optional argument REAL is non-nil, return a real floating point 310If optional argument REAL is non-nil, return a real floating point
308number instead of a rounded integer value." 311number instead of a rounded integer value."
309 (funcall (if real '/ 'ceiling) 312 (fringe-columns 'right real))
310 (or (nth 1 (window-fringes)) 0)
311 (float (frame-char-width))))
312
313(defun ruler-mode-scroll-bar-cols (side)
314 "Return the width, measured in columns, of the vertical scrollbar on SIDE.
315SIDE must be the symbol `left' or `right'."
316 (let* ((wsb (window-scroll-bars))
317 (vtype (nth 2 wsb))
318 (cols (nth 1 wsb)))
319 (cond
320 ((not (memq side '(left right)))
321 (error "`left' or `right' expected instead of %S" side))
322 ((and (eq vtype side) cols))
323 ((eq (frame-parameter nil 'vertical-scroll-bars) side)
324 ;; nil means it's a non-toolkit scroll bar, and its width in
325 ;; columns is 14 pixels rounded up.
326 (ceiling (or (frame-parameter nil 'scroll-bar-width) 14)
327 (frame-char-width)))
328 (0))))
329 313
330(defmacro ruler-mode-right-scroll-bar-cols () 314(defmacro ruler-mode-right-scroll-bar-cols ()
331 "Return the width, measured in columns, of the right vertical scrollbar." 315 "Return the width, measured in columns, of the right vertical scrollbar."
332 '(ruler-mode-scroll-bar-cols 'right)) 316 '(scroll-bar-columns 'right))
333 317
334(defmacro ruler-mode-left-scroll-bar-cols () 318(defmacro ruler-mode-left-scroll-bar-cols ()
335 "Return the width, measured in columns, of the left vertical scrollbar." 319 "Return the width, measured in columns, of the left vertical scrollbar."
336 '(ruler-mode-scroll-bar-cols 'left)) 320 '(scroll-bar-columns 'left))
337 321
338(defsubst ruler-mode-full-window-width () 322(defsubst ruler-mode-full-window-width ()
339 "Return the full width of the selected window." 323 "Return the full width of the selected window."
@@ -568,9 +552,17 @@ START-EVENT is the mouse click event."
568 "Hold previous value of `header-line-format'.") 552 "Hold previous value of `header-line-format'.")
569(make-variable-buffer-local 'ruler-mode-header-line-format-old) 553(make-variable-buffer-local 'ruler-mode-header-line-format-old)
570 554
555(defvar ruler-mode-ruler-function nil
556 "If non-nil, function to call to return ruler string.
557This variable is expected to be made buffer-local by modes.")
558
571(defconst ruler-mode-header-line-format 559(defconst ruler-mode-header-line-format
572 '(:eval (ruler-mode-ruler)) 560 '(:eval (funcall (if ruler-mode-ruler-function
573 "`header-line-format' used in ruler mode.") 561 ruler-mode-ruler-function
562 'ruler-mode-ruler)))
563 "`header-line-format' used in ruler mode.
564If the non-nil value for ruler-mode-ruler-function is given, use it.
565Else use `ruler-mode-ruler' is used as default value.")
574 566
575;;;###autoload 567;;;###autoload
576(define-minor-mode ruler-mode 568(define-minor-mode ruler-mode
diff --git a/lisp/scroll-bar.el b/lisp/scroll-bar.el
index a2f2d22da5d..2d2921e9fc9 100644
--- a/lisp/scroll-bar.el
+++ b/lisp/scroll-bar.el
@@ -54,6 +54,23 @@ that scroll bar position."
54 ;; with a large scroll bar portion can easily overflow a lisp int. 54 ;; with a large scroll bar portion can easily overflow a lisp int.
55 (truncate (/ (* (float (car num-denom)) whole) (cdr num-denom)))) 55 (truncate (/ (* (float (car num-denom)) whole) (cdr num-denom))))
56 56
57(defun scroll-bar-columns (side)
58 "Return the width, measured in columns, of the vertical scrollbar on SIDE.
59SIDE must be the symbol `left' or `right'."
60 (let* ((wsb (window-scroll-bars))
61 (vtype (nth 2 wsb))
62 (cols (nth 1 wsb)))
63 (cond
64 ((not (memq side '(left right)))
65 (error "`left' or `right' expected instead of %S" side))
66 ((and (eq vtype side) cols))
67 ((eq (frame-parameter nil 'vertical-scroll-bars) side)
68 ;; nil means it's a non-toolkit scroll bar, and its width in
69 ;; columns is 14 pixels rounded up.
70 (ceiling (or (frame-parameter nil 'scroll-bar-width) 14)
71 (frame-char-width)))
72 (0))))
73
57 74
58;;;; Helpful functions for enabling and disabling scroll bars. 75;;;; Helpful functions for enabling and disabling scroll bars.
59 76