1 ;;; fringe.el --- fringe setup and control -*- coding: utf-8 -*-
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 ;; 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Simon Josefsson <simon@josefsson.org>
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; This file contains code to initialize the built-in fringe bitmaps
29 ;; as well as helpful functions for customizing the appearance of the
32 ;; The code is influenced by scroll-bar.el and avoid.el. The author
33 ;; gratefully acknowledge comments and suggestions made by Miles
34 ;; Bader, Eli Zaretski, Richard Stallman, Pavel JanÃk and others which
35 ;; improved this package.
44 ;; Define the built-in fringe bitmaps and setup default mappings
46 (when (boundp 'fringe-bitmaps
)
47 (let ((bitmaps '(question-mark
48 left-arrow right-arrow up-arrow down-arrow
49 left-curly-arrow right-curly-arrow
50 left-triangle right-triangle
51 top-left-angle top-right-angle
52 bottom-left-angle bottom-right-angle
53 left-bracket right-bracket
54 filled-rectangle hollow-rectangle
55 filled-square hollow-square
56 vertical-bar horizontal-bar
60 (push (car bitmaps
) fringe-bitmaps
)
61 (put (car bitmaps
) 'fringe bn
)
62 (setq bitmaps
(cdr bitmaps
)
65 (setq-default fringe-indicator-alist
66 '((truncation .
(left-arrow right-arrow
))
67 (continuation .
(left-curly-arrow right-curly-arrow
))
68 (overlay-arrow . right-triangle
)
71 (top .
(top-left-angle top-right-angle
))
72 (bottom .
(bottom-left-angle bottom-right-angle
73 top-right-angle top-left-angle
))
74 (top-bottom .
(left-bracket right-bracket
75 top-right-angle top-left-angle
))
76 (empty-line . empty-line
)
77 (unknown . question-mark
)))
79 (setq-default fringe-cursor-alist
80 '((box . filled-rectangle
)
81 (hollow . hollow-rectangle
)
83 (hbar . horizontal-bar
)
84 (hollow-small . hollow-square
))))
87 (defmacro fringe-bitmap-p
(symbol)
88 "Return non-nil if SYMBOL is a fringe bitmap."
89 `(get ,symbol
'fringe
))
92 ;; Control presence of fringes
96 (defvar fringe-mode-explicit nil
97 "Non-nil means `set-fringe-mode' should really do something.
98 This is nil while loading `fringe.el', and t afterward.")
100 (defun set-fringe-mode-1 (ignore value
)
101 "Call `set-fringe-mode' with VALUE.
102 See `fringe-mode' for valid values and their effect.
103 This is usually invoked when setting `fringe-mode' via customize."
104 (set-fringe-mode value
))
106 (defun set-fringe-mode (value)
107 "Set `fringe-mode' to VALUE and put the new value into effect.
108 See `fringe-mode' for possible values and their effect."
109 (setq fringe-mode value
)
111 (when fringe-mode-explicit
112 (modify-all-frames-parameters
113 (list (cons 'left-fringe
(if (consp fringe-mode
)
116 (cons 'right-fringe
(if (consp fringe-mode
)
120 ;; For initialization of fringe-mode, take account of changes
121 ;; made explicitly to default-frame-alist.
122 (defun fringe-mode-initialize (symbol value
)
123 (let* ((left-pair (assq 'left-fringe default-frame-alist
))
124 (right-pair (assq 'right-fringe default-frame-alist
))
125 (left (cdr left-pair
))
126 (right (cdr right-pair
)))
127 (if (or left-pair right-pair
)
128 ;; If there's something in default-frame-alist for fringes,
129 ;; don't change it, but reflect that into the value of fringe-mode.
131 (setq fringe-mode
(cons left right
))
132 (if (equal fringe-mode
'(nil . nil
))
133 (setq fringe-mode nil
))
134 (if (equal fringe-mode
'(0 .
0))
135 (setq fringe-mode
0)))
136 ;; Otherwise impose the user-specified value of fringe-mode.
137 (custom-initialize-reset symbol value
))))
139 (defconst fringe-styles
142 ("right-only" .
(0 . nil
))
143 ("left-only" .
(nil .
0))
144 ("half-width" .
(4 .
4))
145 ("minimal" .
(1 .
1))))
147 (defcustom fringe-mode nil
148 "Specify appearance of fringes on all frames.
149 This variable can be nil (the default) meaning the fringes should have
150 the default width (8 pixels), it can be an integer value specifying
151 the width of both left and right fringe (where 0 means no fringe), or
152 a cons cell where car indicates width of left fringe and cdr indicates
153 width of right fringe (where again 0 can be used to indicate no
155 Note that the actual width may be rounded up to ensure that the sum of
156 the width of the left and right fringes is a multiple of the frame's
157 character width. However, a fringe width of 0 is never rounded.
158 To set this variable in a Lisp program, use `set-fringe-mode' to make
160 Setting the variable with a customization buffer also takes effect.
161 If you only want to modify the appearance of the fringe in one frame,
162 you can use the interactive function `set-fringe-style'."
164 ,@ (mapcar (lambda (style)
166 (replace-regexp-in-string "-" " " (car style
))))
168 ,(concat (capitalize (substring name
0 1))
172 (integer :tag
"Specific width")
173 (cons :tag
"Different left/right sizes"
174 (integer :tag
"Left width")
175 (integer :tag
"Right width")))
178 :initialize
'fringe-mode-initialize
179 :set
'set-fringe-mode-1
)
181 ;; We just set fringe-mode, but that was the default.
182 ;; If it is set again, that is for real.
183 (setq fringe-mode-explicit t
)
185 (defun fringe-query-style (&optional all-frames
)
186 "Query user for fringe style.
187 Returns values suitable for left-fringe and right-fringe frame parameters.
188 If ALL-FRAMES, the negation of the fringe values in
189 `default-frame-alist' is used when user enters the empty string.
190 Otherwise the negation of the fringe value in the currently selected
191 frame parameter is used."
192 (let* ((mode (completing-read
194 "Select fringe mode for "
195 (if all-frames
"all frames" "selected frame")
196 " (type ? for list): ")
197 fringe-styles nil t
))
198 (style (assoc (downcase mode
) fringe-styles
)))
199 (if style
(cdr style
)
200 (if (eq 0 (cdr (assq 'left-fringe
203 (frame-parameters (selected-frame))))))
207 (defun fringe-mode (&optional mode
)
208 "Set the default appearance of fringes on all frames.
210 When called interactively, query the user for MODE. Valid values
211 for MODE include `none', `default', `left-only', `right-only',
212 `minimal' and `half'.
214 When used in a Lisp program, MODE can be a cons cell where the
215 integer in car specifies the left fringe width and the integer in
216 cdr specifies the right fringe width. MODE can also be a single
217 integer that specifies both the left and the right fringe width.
218 If a fringe width specification is nil, that means to use the
219 default width (8 pixels). This command may round up the left and
220 right width specifications to ensure that their sum is a multiple
221 of the character width of a frame. It never rounds up a fringe
224 Fringe widths set by `set-window-fringes' override the default
225 fringe widths set by this command. This command applies to all
226 frames that exist and frames to be created in the future. If you
227 want to set the default appearance of fringes on the selected
228 frame only, see the command `set-fringe-style'."
229 (interactive (list (fringe-query-style 'all-frames
)))
230 (set-fringe-mode mode
))
232 (defun set-fringe-style (&optional mode
)
233 "Set the default appearance of fringes on the selected frame.
235 When called interactively, query the user for MODE. Valid values
236 for MODE include `none', `default', `left-only', `right-only',
237 `minimal' and `half'.
239 When used in a Lisp program, MODE can be a cons cell where the
240 integer in car specifies the left fringe width and the integer in
241 cdr specifies the right fringe width. MODE can also be a single
242 integer that specifies both the left and the right fringe width.
243 If a fringe width specification is nil, that means to use the
244 default width (8 pixels). This command may round up the left and
245 right width specifications to ensure that their sum is a multiple
246 of the character width of a frame. It never rounds up a fringe
249 Fringe widths set by `set-window-fringes' override the default
250 fringe widths set by this command. If you want to set the
251 default appearance of fringes on all frames, see the command
253 (interactive (list (fringe-query-style)))
254 (modify-frame-parameters
256 (list (cons 'left-fringe
(if (consp mode
) (car mode
) mode
))
257 (cons 'right-fringe
(if (consp mode
) (cdr mode
) mode
)))))
259 (defsubst fringe-columns
(side &optional real
)
260 "Return the width, measured in columns, of the fringe area on SIDE.
261 If optional argument REAL is non-nil, return a real floating point
262 number instead of a rounded integer value.
263 SIDE must be the symbol `left' or `right'."
264 (funcall (if real
'/ 'ceiling
)
265 (or (funcall (if (eq side
'left
) 'car
'cadr
)
268 (float (frame-char-width))))
272 ;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d
273 ;;; fringe.el ends here