1 ;;; fringe.el --- change fringes appearance in various ways
3 ;; Copyright (C) 2002, 2003 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., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, 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.
38 ;; Standard fringe bitmaps
40 (defmacro fringe-bitmap-p
(symbol)
41 "Return non-nil if SYMBOL is a fringe bitmap."
42 `(get ,symbol
'fringe
))
44 (defvar fringe-bitmaps
)
46 (unless (or (not (boundp 'fringe-bitmaps
))
47 (get 'left-truncation
'fringe
))
48 (let ((bitmaps '(left-truncation right-truncation
50 continued-line continuation-line
52 top-left-angle top-right-angle
53 bottom-left-angle bottom-right-angle
54 left-bracket right-bracket
55 filled-box-cursor hollow-box-cursor hollow-square
56 bar-cursor hbar-cursor
60 (push (car bitmaps
) fringe-bitmaps
)
61 (put (car bitmaps
) 'fringe bn
)
62 (setq bitmaps
(cdr bitmaps
)
66 ;; Control presence of fringes
70 (defun set-fringe-mode-1 (ignore value
)
71 "Call `set-fringe-mode' with VALUE.
72 See `fringe-mode' for valid values and their effect.
73 This is usually invoked when setting `fringe-mode' via customize."
74 (set-fringe-mode value
))
76 (defun set-fringe-mode (value)
77 "Set `fringe-mode' to VALUE and put the new value into effect.
78 See `fringe-mode' for possible values and their effect."
79 (setq fringe-mode value
)
81 ;; Apply it to default-frame-alist.
82 (let ((parameter (assq 'left-fringe default-frame-alist
)))
84 (setcdr parameter
(if (consp fringe-mode
)
87 (setq default-frame-alist
88 (cons (cons 'left-fringe
(if (consp fringe-mode
)
91 default-frame-alist
))))
92 (let ((parameter (assq 'right-fringe default-frame-alist
)))
94 (setcdr parameter
(if (consp fringe-mode
)
97 (setq default-frame-alist
98 (cons (cons 'right-fringe
(if (consp fringe-mode
)
101 default-frame-alist
))))
103 ;; Apply it to existing frames.
104 (let ((frames (frame-list)))
106 (modify-frame-parameters
108 (list (cons 'left-fringe
(if (consp fringe-mode
)
111 (cons 'right-fringe
(if (consp fringe-mode
)
114 (setq frames
(cdr frames
)))))
116 ;; For initialization of fringe-mode, take account of changes
117 ;; made explicitly to default-frame-alist.
118 (defun fringe-mode-initialize (symbol value
)
119 (let* ((left-pair (assq 'left-fringe default-frame-alist
))
120 (right-pair (assq 'right-fringe default-frame-alist
))
121 (left (cdr left-pair
))
122 (right (cdr right-pair
)))
123 (if (or left-pair right-pair
)
124 ;; If there's something in default-frame-alist for fringes,
125 ;; don't change it, but reflect that into the value of fringe-mode.
127 (setq fringe-mode
(cons left right
))
128 (if (equal fringe-mode
'(nil . nil
))
129 (setq fringe-mode nil
))
130 (if (equal fringe-mode
'(0 .
0))
131 (setq fringe-mode
0)))
132 ;; Otherwise impose the user-specified value of fringe-mode.
133 (custom-initialize-reset symbol value
))))
136 (defcustom fringe-mode nil
137 "*Specify appearance of fringes on all frames.
138 This variable can be nil (the default) meaning the fringes should have
139 the default width (8 pixels), it can be an integer value specifying
140 the width of both left and right fringe (where 0 means no fringe), or
141 a cons cell where car indicates width of left fringe and cdr indicates
142 width of right fringe (where again 0 can be used to indicate no
144 To set this variable in a Lisp program, use `set-fringe-mode' to make
146 Setting the variable with a customization buffer also takes effect.
147 If you only want to modify the appearance of the fringe in one frame,
148 you can use the interactive function `toggle-fringe'"
149 :type
'(choice (const :tag
"Default width" nil
)
150 (const :tag
"No fringes" 0)
151 (const :tag
"Only right" (0 . nil
))
152 (const :tag
"Only left" (nil .
0))
153 (const :tag
"Half width" (5 .
5))
154 (const :tag
"Minimal" (1 .
1))
155 (integer :tag
"Specific width")
156 (cons :tag
"Different left/right sizes"
157 (integer :tag
"Left width")
158 (integer :tag
"Right width")))
161 :initialize
'fringe-mode-initialize
162 :set
'set-fringe-mode-1
)
164 (defun fringe-query-style (&optional all-frames
)
165 "Query user for fringe style.
166 Returns values suitable for left-fringe and right-fringe frame parameters.
167 If ALL-FRAMES, the negation of the fringe values in
168 `default-frame-alist' is used when user enters the empty string.
169 Otherwise the negation of the fringe value in the currently selected
170 frame parameter is used."
171 (let ((mode (intern (completing-read
172 "Select fringe mode for all frames (type ? for list): "
173 '(("none") ("default") ("left-only")
174 ("right-only") ("half") ("minimal"))
176 (cond ((eq mode
'none
) 0)
177 ((eq mode
'default
) nil
)
178 ((eq mode
'left-only
) '(nil .
0))
179 ((eq mode
'right-only
) '(0 . nil
))
180 ((eq mode
'half
) '(5 .
5))
181 ((eq mode
'minimal
) '(1 .
1))
182 ((eq mode
(intern ""))
183 (if (eq 0 (cdr (assq 'left-fringe
186 (frame-parameters (selected-frame))))))
191 (defun fringe-mode (&optional mode
)
192 "Set the default appearance of fringes on all frames.
194 When called interactively, query the user for MODE. Valid values
195 for MODE include `none', `default', `left-only', `right-only',
196 `minimal' and `half'.
198 When used in a Lisp program, MODE can be a cons cell where the
199 integer in car specifies the left fringe width and the integer in
200 cdr specifies the right fringe width. MODE can also be a single
201 integer that specifies both the left and the right fringe width.
202 If a fringe width specification is nil, that means to use the
203 default width (8 pixels). This command may round up the left and
204 right width specifications to ensure that their sum is a multiple
205 of the character width of a frame. It never rounds up a fringe
208 Fringe widths set by `set-window-fringes' override the default
209 fringe widths set by this command. This command applies to all
210 frames that exist and frames to be created in the future. If you
211 want to set the default appearance of fringes on the selected
212 frame only, see the command `set-fringe-style'."
213 (interactive (list (fringe-query-style 'all-frames
)))
214 (set-fringe-mode mode
))
217 (defun set-fringe-style (&optional mode
)
218 "Set the default appearance of fringes on the selected frame.
220 When called interactively, query the user for MODE. Valid values
221 for MODE include `none', `default', `left-only', `right-only',
222 `minimal' and `half'.
224 When used in a Lisp program, MODE can be a cons cell where the
225 integer in car specifies the left fringe width and the integer in
226 cdr specifies the right fringe width. MODE can also be a single
227 integer that specifies both the left and the right fringe width.
228 If a fringe width specification is nil, that means to use the
229 default width (8 pixels). This command may round up the left and
230 right width specifications to ensure that their sum is a multiple
231 of the character width of a frame. It never rounds up a fringe
234 Fringe widths set by `set-window-fringes' override the default
235 fringe widths set by this command. If you want to set the
236 default appearance of fringes on all frames, see the command
238 (interactive (list (fringe-query-style)))
239 (modify-frame-parameters
241 (list (cons 'left-fringe
(if (consp mode
) (car mode
) mode
))
242 (cons 'right-fringe
(if (consp mode
) (cdr mode
) mode
)))))
244 (defsubst fringe-columns
(side &optional real
)
245 "Return the width, measured in columns, of the fringe area on SIDE.
246 If optional argument REAL is non-nil, return a real floating point
247 number instead of a rounded integer value.
248 SIDE must be the symbol `left' or `right'."
249 (funcall (if real
'/ 'ceiling
)
250 (or (funcall (if (eq side
'left
) 'car
'cadr
)
253 (float (frame-char-width))))
257 ;;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d
258 ;;; fringe.el ends here