* net/rcirc.el (rcirc): Use correct property names (Bug#3037).
[emacs.git] / lisp / fringe.el
blob4484aa7e584fc506147f558af4a2d3252c926fc8
1 ;;; fringe.el --- fringe setup and control
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 ;; 2009 Free Software Foundation, Inc.
6 ;; Author: Simon Josefsson <simon@josefsson.org>
7 ;; Maintainer: FSF
8 ;; Keywords: frames
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; This file contains code to initialize the built-in fringe bitmaps
28 ;; as well as helpful functions for customizing the appearance of the
29 ;; fringe.
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.
36 ;;; Code:
38 (defgroup fringe nil
39 "Window fringes."
40 :version "22.1"
41 :group 'frames)
43 ;; Define the built-in fringe bitmaps and setup default mappings
45 (when (boundp 'fringe-bitmaps)
46 (let ((bitmaps '(question-mark
47 left-arrow right-arrow up-arrow down-arrow
48 left-curly-arrow right-curly-arrow
49 left-triangle right-triangle
50 top-left-angle top-right-angle
51 bottom-left-angle bottom-right-angle
52 left-bracket right-bracket
53 filled-rectangle hollow-rectangle
54 filled-square hollow-square
55 vertical-bar horizontal-bar
56 empty-line))
57 (bn 1))
58 (while bitmaps
59 (push (car bitmaps) fringe-bitmaps)
60 (put (car bitmaps) 'fringe bn)
61 (setq bitmaps (cdr bitmaps)
62 bn (1+ bn))))
64 (setq-default fringe-indicator-alist
65 '((truncation . (left-arrow right-arrow))
66 (continuation . (left-curly-arrow right-curly-arrow))
67 (overlay-arrow . right-triangle)
68 (up . up-arrow)
69 (down . down-arrow)
70 (top . (top-left-angle top-right-angle))
71 (bottom . (bottom-left-angle bottom-right-angle
72 top-right-angle top-left-angle))
73 (top-bottom . (left-bracket right-bracket
74 top-right-angle top-left-angle))
75 (empty-line . empty-line)
76 (unknown . question-mark)))
78 (setq-default fringe-cursor-alist
79 '((box . filled-rectangle)
80 (hollow . hollow-rectangle)
81 (bar . vertical-bar)
82 (hbar . horizontal-bar)
83 (hollow-small . hollow-square))))
86 (defmacro fringe-bitmap-p (symbol)
87 "Return non-nil if SYMBOL is a fringe bitmap."
88 `(get ,symbol 'fringe))
91 ;; Control presence of fringes
93 (defvar fringe-mode)
95 (defvar fringe-mode-explicit nil
96 "Non-nil means `set-fringe-mode' should really do something.
97 This is nil while loading `fringe.el', and t afterward.")
99 (defun set-fringe-mode-1 (ignore value)
100 "Call `set-fringe-mode' with VALUE.
101 See `fringe-mode' for valid values and their effect.
102 This is usually invoked when setting `fringe-mode' via customize."
103 (set-fringe-mode value))
105 (defun set-fringe-mode (value)
106 "Set `fringe-mode' to VALUE and put the new value into effect.
107 See `fringe-mode' for possible values and their effect."
108 (setq fringe-mode value)
110 (when fringe-mode-explicit
111 (modify-all-frames-parameters
112 (list (cons 'left-fringe (if (consp fringe-mode)
113 (car fringe-mode)
114 fringe-mode))
115 (cons 'right-fringe (if (consp fringe-mode)
116 (cdr fringe-mode)
117 fringe-mode))))))
119 ;; For initialization of fringe-mode, take account of changes
120 ;; made explicitly to default-frame-alist.
121 (defun fringe-mode-initialize (symbol value)
122 (let* ((left-pair (assq 'left-fringe default-frame-alist))
123 (right-pair (assq 'right-fringe default-frame-alist))
124 (left (cdr left-pair))
125 (right (cdr right-pair)))
126 (if (or left-pair right-pair)
127 ;; If there's something in default-frame-alist for fringes,
128 ;; don't change it, but reflect that into the value of fringe-mode.
129 (progn
130 (setq fringe-mode (cons left right))
131 (if (equal fringe-mode '(nil . nil))
132 (setq fringe-mode nil))
133 (if (equal fringe-mode '(0 . 0))
134 (setq fringe-mode 0)))
135 ;; Otherwise impose the user-specified value of fringe-mode.
136 (custom-initialize-reset symbol value))))
138 (defcustom fringe-mode nil
139 "Specify appearance of fringes on all frames.
140 This variable can be nil (the default) meaning the fringes should have
141 the default width (8 pixels), it can be an integer value specifying
142 the width of both left and right fringe (where 0 means no fringe), or
143 a cons cell where car indicates width of left fringe and cdr indicates
144 width of right fringe (where again 0 can be used to indicate no
145 fringe).
146 To set this variable in a Lisp program, use `set-fringe-mode' to make
147 it take real effect.
148 Setting the variable with a customization buffer also takes effect.
149 If you only want to modify the appearance of the fringe in one frame,
150 you can use the interactive function `set-fringe-style'."
151 :type '(choice (const :tag "Default width" nil)
152 (const :tag "No fringes" 0)
153 (const :tag "Only right" (0 . nil))
154 (const :tag "Only left" (nil . 0))
155 (const :tag "Half width" (5 . 5))
156 (const :tag "Minimal" (1 . 1))
157 (integer :tag "Specific width")
158 (cons :tag "Different left/right sizes"
159 (integer :tag "Left width")
160 (integer :tag "Right width")))
161 :group 'fringe
162 :require 'fringe
163 :initialize 'fringe-mode-initialize
164 :set 'set-fringe-mode-1)
166 ;; We just set fringe-mode, but that was the default.
167 ;; If it is set again, that is for real.
168 (setq fringe-mode-explicit t)
170 (defun fringe-query-style (&optional all-frames)
171 "Query user for fringe style.
172 Returns values suitable for left-fringe and right-fringe frame parameters.
173 If ALL-FRAMES, the negation of the fringe values in
174 `default-frame-alist' is used when user enters the empty string.
175 Otherwise the negation of the fringe value in the currently selected
176 frame parameter is used."
177 (let ((mode (intern (completing-read
178 (concat
179 "Select fringe mode for "
180 (if all-frames "all frames" "selected frame")
181 " (type ? for list): ")
182 '(("none") ("default") ("left-only")
183 ("right-only") ("half") ("minimal"))
184 nil t))))
185 (cond ((eq mode 'none) 0)
186 ((eq mode 'default) nil)
187 ((eq mode 'left-only) '(nil . 0))
188 ((eq mode 'right-only) '(0 . nil))
189 ((eq mode 'half) '(5 . 5))
190 ((eq mode 'minimal) '(1 . 1))
191 ((eq mode (intern ""))
192 (if (eq 0 (cdr (assq 'left-fringe
193 (if all-frames
194 default-frame-alist
195 (frame-parameters (selected-frame))))))
197 0)))))
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
214 width of 0.
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))
224 (defun set-fringe-style (&optional mode)
225 "Set the default appearance of fringes on the selected frame.
227 When called interactively, query the user for MODE. Valid values
228 for MODE include `none', `default', `left-only', `right-only',
229 `minimal' and `half'.
231 When used in a Lisp program, MODE can be a cons cell where the
232 integer in car specifies the left fringe width and the integer in
233 cdr specifies the right fringe width. MODE can also be a single
234 integer that specifies both the left and the right fringe width.
235 If a fringe width specification is nil, that means to use the
236 default width (8 pixels). This command may round up the left and
237 right width specifications to ensure that their sum is a multiple
238 of the character width of a frame. It never rounds up a fringe
239 width of 0.
241 Fringe widths set by `set-window-fringes' override the default
242 fringe widths set by this command. If you want to set the
243 default appearance of fringes on all frames, see the command
244 `fringe-mode'."
245 (interactive (list (fringe-query-style)))
246 (modify-frame-parameters
247 (selected-frame)
248 (list (cons 'left-fringe (if (consp mode) (car mode) mode))
249 (cons 'right-fringe (if (consp mode) (cdr mode) mode)))))
251 (defsubst fringe-columns (side &optional real)
252 "Return the width, measured in columns, of the fringe area on SIDE.
253 If optional argument REAL is non-nil, return a real floating point
254 number instead of a rounded integer value.
255 SIDE must be the symbol `left' or `right'."
256 (funcall (if real '/ 'ceiling)
257 (or (funcall (if (eq side 'left) 'car 'cadr)
258 (window-fringes))
260 (float (frame-char-width))))
262 (provide 'fringe)
264 ;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d
265 ;;; fringe.el ends here