Merge from emacs--devo--0
[bpt/emacs.git] / lisp / fringe.el
1 ;;; fringe.el --- fringe setup and control
2
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
4
5 ;; Author: Simon Josefsson <simon@josefsson.org>
6 ;; Maintainer: FSF
7 ;; Keywords: frames
8
9 ;; This file is part of GNU Emacs.
10
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 3, or (at your option)
14 ;; any later version.
15
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.
20
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.
25
26 ;;; Commentary:
27
28 ;; This file contains code to initialize the built-in fringe bitmaps
29 ;; as well as helpful functions for customizing the appearance of the
30 ;; fringe.
31
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.
36
37 ;;; Code:
38
39 (defgroup fringe nil
40 "Window fringes."
41 :version "22.1"
42 :group 'frames)
43
44 ;; Define the built-in fringe bitmaps and setup default mappings
45
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
57 empty-line))
58 (bn 1))
59 (while bitmaps
60 (push (car bitmaps) fringe-bitmaps)
61 (put (car bitmaps) 'fringe bn)
62 (setq bitmaps (cdr bitmaps)
63 bn (1+ bn))))
64
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)
69 (up . up-arrow)
70 (down . down-arrow)
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)))
78
79 (setq-default fringe-cursor-alist
80 '((box . filled-rectangle)
81 (hollow . hollow-rectangle)
82 (bar . vertical-bar)
83 (hbar . horizontal-bar)
84 (hollow-small . hollow-square))))
85
86
87 (defmacro fringe-bitmap-p (symbol)
88 "Return non-nil if SYMBOL is a fringe bitmap."
89 `(get ,symbol 'fringe))
90
91
92 ;; Control presence of fringes
93
94 (defvar fringe-mode)
95
96 (defun set-fringe-mode-1 (ignore value)
97 "Call `set-fringe-mode' with VALUE.
98 See `fringe-mode' for valid values and their effect.
99 This is usually invoked when setting `fringe-mode' via customize."
100 (set-fringe-mode value))
101
102 (defun set-fringe-mode (value)
103 "Set `fringe-mode' to VALUE and put the new value into effect.
104 See `fringe-mode' for possible values and their effect."
105 (setq fringe-mode value)
106
107 (modify-all-frames-parameters
108 (list (cons 'left-fringe (if (consp fringe-mode)
109 (car fringe-mode)
110 fringe-mode))
111 (cons 'right-fringe (if (consp fringe-mode)
112 (cdr fringe-mode)
113 fringe-mode)))))
114
115 ;; For initialization of fringe-mode, take account of changes
116 ;; made explicitly to default-frame-alist.
117 (defun fringe-mode-initialize (symbol value)
118 (let* ((left-pair (assq 'left-fringe default-frame-alist))
119 (right-pair (assq 'right-fringe default-frame-alist))
120 (left (cdr left-pair))
121 (right (cdr right-pair)))
122 (if (or left-pair right-pair)
123 ;; If there's something in default-frame-alist for fringes,
124 ;; don't change it, but reflect that into the value of fringe-mode.
125 (progn
126 (setq fringe-mode (cons left right))
127 (if (equal fringe-mode '(nil . nil))
128 (setq fringe-mode nil))
129 (if (equal fringe-mode '(0 . 0))
130 (setq fringe-mode 0)))
131 ;; Otherwise impose the user-specified value of fringe-mode.
132 (custom-initialize-reset symbol value))))
133
134 (defcustom fringe-mode nil
135 "*Specify appearance of fringes on all frames.
136 This variable can be nil (the default) meaning the fringes should have
137 the default width (8 pixels), it can be an integer value specifying
138 the width of both left and right fringe (where 0 means no fringe), or
139 a cons cell where car indicates width of left fringe and cdr indicates
140 width of right fringe (where again 0 can be used to indicate no
141 fringe).
142 To set this variable in a Lisp program, use `set-fringe-mode' to make
143 it take real effect.
144 Setting the variable with a customization buffer also takes effect.
145 If you only want to modify the appearance of the fringe in one frame,
146 you can use the interactive function `set-fringe-style'."
147 :type '(choice (const :tag "Default width" nil)
148 (const :tag "No fringes" 0)
149 (const :tag "Only right" (0 . nil))
150 (const :tag "Only left" (nil . 0))
151 (const :tag "Half width" (5 . 5))
152 (const :tag "Minimal" (1 . 1))
153 (integer :tag "Specific width")
154 (cons :tag "Different left/right sizes"
155 (integer :tag "Left width")
156 (integer :tag "Right width")))
157 :group 'fringe
158 :require 'fringe
159 :initialize 'fringe-mode-initialize
160 :set 'set-fringe-mode-1)
161
162 (defun fringe-query-style (&optional all-frames)
163 "Query user for fringe style.
164 Returns values suitable for left-fringe and right-fringe frame parameters.
165 If ALL-FRAMES, the negation of the fringe values in
166 `default-frame-alist' is used when user enters the empty string.
167 Otherwise the negation of the fringe value in the currently selected
168 frame parameter is used."
169 (let ((mode (intern (completing-read
170 (concat
171 "Select fringe mode for "
172 (if all-frames "all frames" "selected frame")
173 " (type ? for list): ")
174 '(("none") ("default") ("left-only")
175 ("right-only") ("half") ("minimal"))
176 nil t))))
177 (cond ((eq mode 'none) 0)
178 ((eq mode 'default) nil)
179 ((eq mode 'left-only) '(nil . 0))
180 ((eq mode 'right-only) '(0 . nil))
181 ((eq mode 'half) '(5 . 5))
182 ((eq mode 'minimal) '(1 . 1))
183 ((eq mode (intern ""))
184 (if (eq 0 (cdr (assq 'left-fringe
185 (if all-frames
186 default-frame-alist
187 (frame-parameters (selected-frame))))))
188 nil
189 0)))))
190
191 (defun fringe-mode (&optional mode)
192 "Set the default appearance of fringes on all frames.
193
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'.
197
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
206 width of 0.
207
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))
215
216 (defun set-fringe-style (&optional mode)
217 "Set the default appearance of fringes on the selected frame.
218
219 When called interactively, query the user for MODE. Valid values
220 for MODE include `none', `default', `left-only', `right-only',
221 `minimal' and `half'.
222
223 When used in a Lisp program, MODE can be a cons cell where the
224 integer in car specifies the left fringe width and the integer in
225 cdr specifies the right fringe width. MODE can also be a single
226 integer that specifies both the left and the right fringe width.
227 If a fringe width specification is nil, that means to use the
228 default width (8 pixels). This command may round up the left and
229 right width specifications to ensure that their sum is a multiple
230 of the character width of a frame. It never rounds up a fringe
231 width of 0.
232
233 Fringe widths set by `set-window-fringes' override the default
234 fringe widths set by this command. If you want to set the
235 default appearance of fringes on all frames, see the command
236 `fringe-mode'."
237 (interactive (list (fringe-query-style)))
238 (modify-frame-parameters
239 (selected-frame)
240 (list (cons 'left-fringe (if (consp mode) (car mode) mode))
241 (cons 'right-fringe (if (consp mode) (cdr mode) mode)))))
242
243 (defsubst fringe-columns (side &optional real)
244 "Return the width, measured in columns, of the fringe area on SIDE.
245 If optional argument REAL is non-nil, return a real floating point
246 number instead of a rounded integer value.
247 SIDE must be the symbol `left' or `right'."
248 (funcall (if real '/ 'ceiling)
249 (or (funcall (if (eq side 'left) 'car 'cadr)
250 (window-fringes))
251 0)
252 (float (frame-char-width))))
253
254 (provide 'fringe)
255
256 ;;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d
257 ;;; fringe.el ends here