Regenerate autotools stuff, grumble.
[emacs.git] / lisp / fringe.el
blob7d009b03e76d44e7871539f7397035bf779cc513
1 ;;; fringe.el --- fringe setup and control -*- coding: utf-8 -*-
3 ;; Copyright (C) 2002-2011 Free Software Foundation, Inc.
5 ;; Author: Simon Josefsson <simon@josefsson.org>
6 ;; Maintainer: FSF
7 ;; Keywords: frames
8 ;; Package: emacs
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 (defconst fringe-styles
139 '(("default" . nil)
140 ("no-fringes" . 0)
141 ("right-only" . (0 . nil))
142 ("left-only" . (nil . 0))
143 ("half-width" . (4 . 4))
144 ("minimal" . (1 . 1))))
146 (defcustom fringe-mode nil
147 "Specify appearance of fringes on all frames.
148 This variable can be nil (the default) meaning the fringes should have
149 the default width (8 pixels), it can be an integer value specifying
150 the width of both left and right fringe (where 0 means no fringe), or
151 a cons cell where car indicates width of left fringe and cdr indicates
152 width of right fringe (where again 0 can be used to indicate no
153 fringe).
154 Note that the actual width may be rounded up to ensure that the sum of
155 the width of the left and right fringes is a multiple of the frame's
156 character width. However, a fringe width of 0 is never rounded.
157 To set this variable in a Lisp program, use `set-fringe-mode' to make
158 it take real effect.
159 Setting the variable with a customization buffer also takes effect.
160 If you only want to modify the appearance of the fringe in one frame,
161 you can use the interactive function `set-fringe-style'."
162 :type `(choice
163 ,@ (mapcar (lambda (style)
164 (let ((name
165 (replace-regexp-in-string "-" " " (car style))))
166 `(const :tag
167 ,(concat (capitalize (substring name 0 1))
168 (substring name 1))
169 ,(cdr style))))
170 fringe-styles)
171 (integer :tag "Specific width")
172 (cons :tag "Different left/right sizes"
173 (integer :tag "Left width")
174 (integer :tag "Right width")))
175 :group 'fringe
176 :require 'fringe
177 :initialize 'fringe-mode-initialize
178 :set 'set-fringe-mode-1)
180 ;; We just set fringe-mode, but that was the default.
181 ;; If it is set again, that is for real.
182 (setq fringe-mode-explicit t)
184 (defun fringe-query-style (&optional all-frames)
185 "Query user for fringe style.
186 Returns values suitable for left-fringe and right-fringe frame parameters.
187 If ALL-FRAMES, the negation of the fringe values in
188 `default-frame-alist' is used when user enters the empty string.
189 Otherwise the negation of the fringe value in the currently selected
190 frame parameter is used."
191 (let* ((mode (completing-read
192 (concat
193 "Select fringe mode for "
194 (if all-frames "all frames" "selected frame")
195 " (type ? for list): ")
196 fringe-styles nil t))
197 (style (assoc (downcase mode) fringe-styles)))
198 (if style (cdr style)
199 (if (eq 0 (cdr (assq 'left-fringe
200 (if all-frames
201 default-frame-alist
202 (frame-parameters (selected-frame))))))
204 0))))
206 (defun fringe-mode (&optional mode)
207 "Set the default appearance of fringes on all frames.
209 When called interactively, query the user for MODE. Valid values
210 for MODE include `none', `default', `left-only', `right-only',
211 `minimal' and `half'.
213 When used in a Lisp program, MODE can be a cons cell where the
214 integer in car specifies the left fringe width and the integer in
215 cdr specifies the right fringe width. MODE can also be a single
216 integer that specifies both the left and the right fringe width.
217 If a fringe width specification is nil, that means to use the
218 default width (8 pixels). This command may round up the left and
219 right width specifications to ensure that their sum is a multiple
220 of the character width of a frame. It never rounds up a fringe
221 width of 0.
223 Fringe widths set by `set-window-fringes' override the default
224 fringe widths set by this command. This command applies to all
225 frames that exist and frames to be created in the future. If you
226 want to set the default appearance of fringes on the selected
227 frame only, see the command `set-fringe-style'."
228 (interactive (list (fringe-query-style 'all-frames)))
229 (set-fringe-mode mode))
231 (defun set-fringe-style (&optional mode)
232 "Set the default appearance of fringes on the selected frame.
234 When called interactively, query the user for MODE. Valid values
235 for MODE include `none', `default', `left-only', `right-only',
236 `minimal' and `half'.
238 When used in a Lisp program, MODE can be a cons cell where the
239 integer in car specifies the left fringe width and the integer in
240 cdr specifies the right fringe width. MODE can also be a single
241 integer that specifies both the left and the right fringe width.
242 If a fringe width specification is nil, that means to use the
243 default width (8 pixels). This command may round up the left and
244 right width specifications to ensure that their sum is a multiple
245 of the character width of a frame. It never rounds up a fringe
246 width of 0.
248 Fringe widths set by `set-window-fringes' override the default
249 fringe widths set by this command. If you want to set the
250 default appearance of fringes on all frames, see the command
251 `fringe-mode'."
252 (interactive (list (fringe-query-style)))
253 (modify-frame-parameters
254 (selected-frame)
255 (list (cons 'left-fringe (if (consp mode) (car mode) mode))
256 (cons 'right-fringe (if (consp mode) (cdr mode) mode)))))
258 (defsubst fringe-columns (side &optional real)
259 "Return the width, measured in columns, of the fringe area on SIDE.
260 If optional argument REAL is non-nil, return a real floating point
261 number instead of a rounded integer value.
262 SIDE must be the symbol `left' or `right'."
263 (funcall (if real '/ 'ceiling)
264 (or (funcall (if (eq side 'left) 'car 'cadr)
265 (window-fringes))
267 (float (frame-char-width))))
269 (provide 'fringe)
271 ;;; fringe.el ends here