Spelling fixes.
[bpt/emacs.git] / lisp / fringe.el
CommitLineData
fdf483c9 1;;; fringe.el --- fringe setup and control -*- coding: utf-8 -*-
02f4566a 2
73b0cd50 3;; Copyright (C) 2002-2011 Free Software Foundation, Inc.
02f4566a
SJ
4
5;; Author: Simon Josefsson <simon@josefsson.org>
6;; Maintainer: FSF
7;; Keywords: frames
bd78fa1d 8;; Package: emacs
02f4566a
SJ
9
10;; This file is part of GNU Emacs.
11
eb3fa2cf 12;; GNU Emacs is free software: you can redistribute it and/or modify
02f4566a 13;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
02f4566a
SJ
16
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.
21
22;; You should have received a copy of the GNU General Public License
eb3fa2cf 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
02f4566a
SJ
24
25;;; Commentary:
26
dd9959da
KS
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.
02f4566a
SJ
30
31;; The code is influenced by scroll-bar.el and avoid.el. The author
32;; gratefully acknowledge comments and suggestions made by Miles
22bcf204 33;; Bader, Eli Zaretskii, Richard Stallman, Pavel Janík and others which
02f4566a
SJ
34;; improved this package.
35
36;;; Code:
37
41e1c123
KS
38(defgroup fringe nil
39 "Window fringes."
bf247b6e 40 :version "22.1"
41e1c123
KS
41 :group 'frames)
42
dd9959da
KS
43;; Define the built-in fringe bitmaps and setup default mappings
44
2870bad9
KS
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))))
63
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)))
77
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))))
c3c6c23c 84
dd9959da
KS
85
86(defmacro fringe-bitmap-p (symbol)
87 "Return non-nil if SYMBOL is a fringe bitmap."
88 `(get ,symbol 'fringe))
89
90
c3c6c23c
KS
91;; Control presence of fringes
92
02f4566a
SJ
93(defvar fringe-mode)
94
f78a91b3
MR
95(defvar fringe-mode-explicit nil
96 "Non-nil means `set-fringe-mode' should really do something.
97This is nil while loading `fringe.el', and t afterward.")
98
06b60517 99(defun set-fringe-mode-1 (_ignore value)
02f4566a
SJ
100 "Call `set-fringe-mode' with VALUE.
101See `fringe-mode' for valid values and their effect.
102This is usually invoked when setting `fringe-mode' via customize."
103 (set-fringe-mode value))
104
105(defun set-fringe-mode (value)
106 "Set `fringe-mode' to VALUE and put the new value into effect.
107See `fringe-mode' for possible values and their effect."
108 (setq fringe-mode value)
109
f78a91b3
MR
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))))))
02f4566a 118
efa0a47a
RS
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))))
137
37c0347e
SM
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))))
145
02f4566a 146(defcustom fringe-mode nil
9201cc28 147 "Specify appearance of fringes on all frames.
02f4566a
SJ
148This variable can be nil (the default) meaning the fringes should have
149the default width (8 pixels), it can be an integer value specifying
150the width of both left and right fringe (where 0 means no fringe), or
151a cons cell where car indicates width of left fringe and cdr indicates
152width of right fringe (where again 0 can be used to indicate no
153fringe).
71b961e8
EZ
154Note that the actual width may be rounded up to ensure that the sum of
155the width of the left and right fringes is a multiple of the frame's
156character width. However, a fringe width of 0 is never rounded.
02f4566a
SJ
157To set this variable in a Lisp program, use `set-fringe-mode' to make
158it take real effect.
159Setting the variable with a customization buffer also takes effect.
160If you only want to modify the appearance of the fringe in one frame,
feed81e9 161you can use the interactive function `set-fringe-style'."
37c0347e
SM
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")))
41e1c123 175 :group 'fringe
02f4566a 176 :require 'fringe
efa0a47a 177 :initialize 'fringe-mode-initialize
02f4566a
SJ
178 :set 'set-fringe-mode-1)
179
f78a91b3
MR
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)
183
02f4566a
SJ
184(defun fringe-query-style (&optional all-frames)
185 "Query user for fringe style.
186Returns values suitable for left-fringe and right-fringe frame parameters.
187If ALL-FRAMES, the negation of the fringe values in
188`default-frame-alist' is used when user enters the empty string.
189Otherwise the negation of the fringe value in the currently selected
190frame parameter is used."
37c0347e
SM
191 (let* ((mode (completing-read
192 (concat
193 "Select fringe mode for "
194 (if all-frames "all frames" "selected frame")
fc00f69c 195 ": ")
37c0347e
SM
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))))))
203 nil
204 0))))
02f4566a 205
02f4566a 206(defun fringe-mode (&optional mode)
1c907043 207 "Set the default appearance of fringes on all frames.
af15cfe8 208
1c907043
LK
209When called interactively, query the user for MODE. Valid values
210for MODE include `none', `default', `left-only', `right-only',
211`minimal' and `half'.
af15cfe8
LK
212
213When used in a Lisp program, MODE can be a cons cell where the
214integer in car specifies the left fringe width and the integer in
215cdr specifies the right fringe width. MODE can also be a single
216integer that specifies both the left and the right fringe width.
1c907043
LK
217If a fringe width specification is nil, that means to use the
218default width (8 pixels). This command may round up the left and
219right width specifications to ensure that their sum is a multiple
220of the character width of a frame. It never rounds up a fringe
221width of 0.
af15cfe8
LK
222
223Fringe widths set by `set-window-fringes' override the default
224fringe widths set by this command. This command applies to all
225frames that exist and frames to be created in the future. If you
226want to set the default appearance of fringes on the selected
227frame only, see the command `set-fringe-style'."
02f4566a
SJ
228 (interactive (list (fringe-query-style 'all-frames)))
229 (set-fringe-mode mode))
230
02f4566a 231(defun set-fringe-style (&optional mode)
1c907043 232 "Set the default appearance of fringes on the selected frame.
af15cfe8 233
1c907043
LK
234When called interactively, query the user for MODE. Valid values
235for MODE include `none', `default', `left-only', `right-only',
236`minimal' and `half'.
af15cfe8
LK
237
238When used in a Lisp program, MODE can be a cons cell where the
239integer in car specifies the left fringe width and the integer in
240cdr specifies the right fringe width. MODE can also be a single
241integer that specifies both the left and the right fringe width.
1c907043
LK
242If a fringe width specification is nil, that means to use the
243default width (8 pixels). This command may round up the left and
244right width specifications to ensure that their sum is a multiple
245of the character width of a frame. It never rounds up a fringe
246width of 0.
af15cfe8
LK
247
248Fringe widths set by `set-window-fringes' override the default
249fringe widths set by this command. If you want to set the
250default appearance of fringes on all frames, see the command
251`fringe-mode'."
02f4566a
SJ
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)))))
257
9fd76d04
MY
258(defsubst fringe-columns (side &optional real)
259 "Return the width, measured in columns, of the fringe area on SIDE.
260If optional argument REAL is non-nil, return a real floating point
261number instead of a rounded integer value.
262SIDE must be the symbol `left' or `right'."
263 (funcall (if real '/ 'ceiling)
264 (or (funcall (if (eq side 'left) 'car 'cadr)
265 (window-fringes))
266 0)
267 (float (frame-char-width))))
822c2a0a 268
02f4566a
SJ
269(provide 'fringe)
270
271;;; fringe.el ends here