1 ;;; fringe.el --- change fringes appearance in various ways
3 ;; Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
5 ;; Author: Simon Josefsson <simon@josefsson.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This file contains helpful functions for customizing the appearance
31 ;; The code is influenced by scroll-bar.el and avoid.el. The author
32 ;; gratefully acknowledge comments and suggestions made by Miles
33 ;; Bader, Eli Zaretski, Richard Stallman, Pavel JanÃk and others which
34 ;; improved this package.
43 ;; Standard fringe bitmaps
45 (defmacro fringe-bitmap-p
(symbol)
46 "Return non-nil if SYMBOL is a fringe bitmap."
47 `(get ,symbol
'fringe
))
49 (defvar fringe-bitmaps
)
51 (unless (or (not (boundp 'fringe-bitmaps
))
52 (get 'left-truncation
'fringe
))
53 (let ((bitmaps '(left-truncation right-truncation
55 continued-line continuation-line
57 top-left-angle top-right-angle
58 bottom-left-angle bottom-right-angle
59 left-bracket right-bracket
60 filled-box-cursor hollow-box-cursor hollow-square
61 bar-cursor hbar-cursor
65 (push (car bitmaps
) fringe-bitmaps
)
66 (put (car bitmaps
) 'fringe bn
)
67 (setq bitmaps
(cdr bitmaps
)
71 ;; Control presence of fringes
75 (defun set-fringe-mode-1 (ignore value
)
76 "Call `set-fringe-mode' with VALUE.
77 See `fringe-mode' for valid values and their effect.
78 This is usually invoked when setting `fringe-mode' via customize."
79 (set-fringe-mode value
))
81 (defun set-fringe-mode (value)
82 "Set `fringe-mode' to VALUE and put the new value into effect.
83 See `fringe-mode' for possible values and their effect."
84 (setq fringe-mode value
)
86 ;; Apply it to default-frame-alist.
87 (let ((parameter (assq 'left-fringe default-frame-alist
)))
89 (setcdr parameter
(if (consp fringe-mode
)
92 (setq default-frame-alist
93 (cons (cons 'left-fringe
(if (consp fringe-mode
)
96 default-frame-alist
))))
97 (let ((parameter (assq 'right-fringe default-frame-alist
)))
99 (setcdr parameter
(if (consp fringe-mode
)
102 (setq default-frame-alist
103 (cons (cons 'right-fringe
(if (consp fringe-mode
)
106 default-frame-alist
))))
108 ;; Apply it to existing frames.
109 (let ((frames (frame-list)))
111 (modify-frame-parameters
113 (list (cons 'left-fringe
(if (consp fringe-mode
)
116 (cons 'right-fringe
(if (consp fringe-mode
)
119 (setq frames
(cdr frames
)))))
121 ;; For initialization of fringe-mode, take account of changes
122 ;; made explicitly to default-frame-alist.
123 (defun fringe-mode-initialize (symbol value
)
124 (let* ((left-pair (assq 'left-fringe default-frame-alist
))
125 (right-pair (assq 'right-fringe default-frame-alist
))
126 (left (cdr left-pair
))
127 (right (cdr right-pair
)))
128 (if (or left-pair right-pair
)
129 ;; If there's something in default-frame-alist for fringes,
130 ;; don't change it, but reflect that into the value of fringe-mode.
132 (setq fringe-mode
(cons left right
))
133 (if (equal fringe-mode
'(nil . nil
))
134 (setq fringe-mode nil
))
135 (if (equal fringe-mode
'(0 .
0))
136 (setq fringe-mode
0)))
137 ;; Otherwise impose the user-specified value of fringe-mode.
138 (custom-initialize-reset symbol value
))))
141 (defcustom fringe-mode nil
142 "*Specify appearance of fringes on all frames.
143 This variable can be nil (the default) meaning the fringes should have
144 the default width (8 pixels), it can be an integer value specifying
145 the width of both left and right fringe (where 0 means no fringe), or
146 a cons cell where car indicates width of left fringe and cdr indicates
147 width of right fringe (where again 0 can be used to indicate no
149 To set this variable in a Lisp program, use `set-fringe-mode' to make
151 Setting the variable with a customization buffer also takes effect.
152 If you only want to modify the appearance of the fringe in one frame,
153 you can use the interactive function `set-fringe-style'."
154 :type
'(choice (const :tag
"Default width" nil
)
155 (const :tag
"No fringes" 0)
156 (const :tag
"Only right" (0 . nil
))
157 (const :tag
"Only left" (nil .
0))
158 (const :tag
"Half width" (5 .
5))
159 (const :tag
"Minimal" (1 .
1))
160 (integer :tag
"Specific width")
161 (cons :tag
"Different left/right sizes"
162 (integer :tag
"Left width")
163 (integer :tag
"Right width")))
166 :initialize
'fringe-mode-initialize
167 :set
'set-fringe-mode-1
)
169 (defun fringe-query-style (&optional all-frames
)
170 "Query user for fringe style.
171 Returns values suitable for left-fringe and right-fringe frame parameters.
172 If ALL-FRAMES, the negation of the fringe values in
173 `default-frame-alist' is used when user enters the empty string.
174 Otherwise the negation of the fringe value in the currently selected
175 frame parameter is used."
176 (let ((mode (intern (completing-read
178 "Select fringe mode for "
179 (if all-frames
"all frames" "selected frame")
180 " (type ? for list): ")
181 '(("none") ("default") ("left-only")
182 ("right-only") ("half") ("minimal"))
184 (cond ((eq mode
'none
) 0)
185 ((eq mode
'default
) nil
)
186 ((eq mode
'left-only
) '(nil .
0))
187 ((eq mode
'right-only
) '(0 . nil
))
188 ((eq mode
'half
) '(5 .
5))
189 ((eq mode
'minimal
) '(1 .
1))
190 ((eq mode
(intern ""))
191 (if (eq 0 (cdr (assq 'left-fringe
194 (frame-parameters (selected-frame))))))
199 (defun fringe-mode (&optional mode
)
200 "Set the default appearance of fringes on all frames.
202 When called interactively, query the user for MODE. Valid values
203 for MODE include `none', `default', `left-only', `right-only',
204 `minimal' and `half'.
206 When used in a Lisp program, MODE can be a cons cell where the
207 integer in car specifies the left fringe width and the integer in
208 cdr specifies the right fringe width. MODE can also be a single
209 integer that specifies both the left and the right fringe width.
210 If a fringe width specification is nil, that means to use the
211 default width (8 pixels). This command may round up the left and
212 right width specifications to ensure that their sum is a multiple
213 of the character width of a frame. It never rounds up a fringe
216 Fringe widths set by `set-window-fringes' override the default
217 fringe widths set by this command. This command applies to all
218 frames that exist and frames to be created in the future. If you
219 want to set the default appearance of fringes on the selected
220 frame only, see the command `set-fringe-style'."
221 (interactive (list (fringe-query-style 'all-frames
)))
222 (set-fringe-mode mode
))
225 (defun set-fringe-style (&optional mode
)
226 "Set the default appearance of fringes on the selected frame.
228 When called interactively, query the user for MODE. Valid values
229 for MODE include `none', `default', `left-only', `right-only',
230 `minimal' and `half'.
232 When used in a Lisp program, MODE can be a cons cell where the
233 integer in car specifies the left fringe width and the integer in
234 cdr specifies the right fringe width. MODE can also be a single
235 integer that specifies both the left and the right fringe width.
236 If a fringe width specification is nil, that means to use the
237 default width (8 pixels). This command may round up the left and
238 right width specifications to ensure that their sum is a multiple
239 of the character width of a frame. It never rounds up a fringe
242 Fringe widths set by `set-window-fringes' override the default
243 fringe widths set by this command. If you want to set the
244 default appearance of fringes on all frames, see the command
246 (interactive (list (fringe-query-style)))
247 (modify-frame-parameters
249 (list (cons 'left-fringe
(if (consp mode
) (car mode
) mode
))
250 (cons 'right-fringe
(if (consp mode
) (cdr mode
) mode
)))))
252 (defsubst fringe-columns
(side &optional real
)
253 "Return the width, measured in columns, of the fringe area on SIDE.
254 If optional argument REAL is non-nil, return a real floating point
255 number instead of a rounded integer value.
256 SIDE must be the symbol `left' or `right'."
257 (funcall (if real
'/ 'ceiling
)
258 (or (funcall (if (eq side
'left
) 'car
'cadr
)
261 (float (frame-char-width))))
263 ;; Fake defvar. Real definition using defcustom is below. The fake
264 ;; defvar is necessary because `fringe-indicators' and
265 ;; `set-fringe-indicators-1' mutually use each other.
266 (defvar fringe-indicators
)
268 (defun set-fringe-indicators-1 (ignore value
)
269 "Set fringe indicators according to VALUE.
270 This is usually invoked when setting `fringe-indicators' via customize."
271 (setq fringe-indicators value
)
272 (setq default-indicate-empty-lines nil
)
273 (setq default-indicate-buffer-boundaries
275 ((memq value
'(left right t
))
278 '((top . left
) (bottom . right
)))
280 '((top . left
) (t . right
)))
282 (setq default-indicate-empty-lines t
)
287 (defcustom fringe-indicators nil
288 "Visually indicate buffer boundaries and scrolling.
289 Setting this variable, changes `default-indicate-buffer-boundaries'."
290 :type
'(choice (const :tag
"No indicators" nil
)
291 (const :tag
"On left" left
)
292 (const :tag
"On right" right
)
293 (const :tag
"Opposite, no arrows" box
)
294 (const :tag
"Opposite, arrows right" mixed
)
295 (const :tag
"Empty lines" empty
))
298 :set
'set-fringe-indicators-1
)
302 ;;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d
303 ;;; fringe.el ends here