Switch to recommended form of GPLv3 permissions notice.
[bpt/emacs.git] / lisp / fringe.el
CommitLineData
dd9959da 1;;; fringe.el --- fringe setup and control
02f4566a 2
409cc4a3 3;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
02f4566a
SJ
4
5;; Author: Simon Josefsson <simon@josefsson.org>
6;; Maintainer: FSF
7;; Keywords: frames
8
9;; This file is part of GNU Emacs.
10
eb3fa2cf 11;; GNU Emacs is free software: you can redistribute it and/or modify
02f4566a 12;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
02f4566a
SJ
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
eb3fa2cf 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
02f4566a
SJ
23
24;;; Commentary:
25
dd9959da
KS
26;; This file contains code to initialize the built-in fringe bitmaps
27;; as well as helpful functions for customizing the appearance of the
28;; fringe.
02f4566a
SJ
29
30;; The code is influenced by scroll-bar.el and avoid.el. The author
31;; gratefully acknowledge comments and suggestions made by Miles
32;; Bader, Eli Zaretski, Richard Stallman, Pavel Janík and others which
33;; improved this package.
34
35;;; Code:
36
41e1c123
KS
37(defgroup fringe nil
38 "Window fringes."
bf247b6e 39 :version "22.1"
41e1c123
KS
40 :group 'frames)
41
dd9959da
KS
42;; Define the built-in fringe bitmaps and setup default mappings
43
2870bad9
KS
44(when (boundp 'fringe-bitmaps)
45 (let ((bitmaps '(question-mark
46 left-arrow right-arrow up-arrow down-arrow
47 left-curly-arrow right-curly-arrow
48 left-triangle right-triangle
49 top-left-angle top-right-angle
50 bottom-left-angle bottom-right-angle
51 left-bracket right-bracket
52 filled-rectangle hollow-rectangle
53 filled-square hollow-square
54 vertical-bar horizontal-bar
55 empty-line))
56 (bn 1))
57 (while bitmaps
58 (push (car bitmaps) fringe-bitmaps)
59 (put (car bitmaps) 'fringe bn)
60 (setq bitmaps (cdr bitmaps)
61 bn (1+ bn))))
62
63 (setq-default fringe-indicator-alist
64 '((truncation . (left-arrow right-arrow))
65 (continuation . (left-curly-arrow right-curly-arrow))
66 (overlay-arrow . right-triangle)
67 (up . up-arrow)
68 (down . down-arrow)
69 (top . (top-left-angle top-right-angle))
70 (bottom . (bottom-left-angle bottom-right-angle
71 top-right-angle top-left-angle))
72 (top-bottom . (left-bracket right-bracket
73 top-right-angle top-left-angle))
74 (empty-line . empty-line)
75 (unknown . question-mark)))
76
77 (setq-default fringe-cursor-alist
78 '((box . filled-rectangle)
79 (hollow . hollow-rectangle)
80 (bar . vertical-bar)
81 (hbar . horizontal-bar)
82 (hollow-small . hollow-square))))
c3c6c23c 83
dd9959da
KS
84
85(defmacro fringe-bitmap-p (symbol)
86 "Return non-nil if SYMBOL is a fringe bitmap."
87 `(get ,symbol 'fringe))
88
89
c3c6c23c
KS
90;; Control presence of fringes
91
02f4566a
SJ
92(defvar fringe-mode)
93
f78a91b3
MR
94(defvar fringe-mode-explicit nil
95 "Non-nil means `set-fringe-mode' should really do something.
96This is nil while loading `fringe.el', and t afterward.")
97
02f4566a
SJ
98(defun set-fringe-mode-1 (ignore value)
99 "Call `set-fringe-mode' with VALUE.
100See `fringe-mode' for valid values and their effect.
101This is usually invoked when setting `fringe-mode' via customize."
102 (set-fringe-mode value))
103
104(defun set-fringe-mode (value)
105 "Set `fringe-mode' to VALUE and put the new value into effect.
106See `fringe-mode' for possible values and their effect."
107 (setq fringe-mode value)
108
f78a91b3
MR
109 (when fringe-mode-explicit
110 (modify-all-frames-parameters
111 (list (cons 'left-fringe (if (consp fringe-mode)
112 (car fringe-mode)
113 fringe-mode))
114 (cons 'right-fringe (if (consp fringe-mode)
115 (cdr fringe-mode)
116 fringe-mode))))))
02f4566a 117
efa0a47a
RS
118;; For initialization of fringe-mode, take account of changes
119;; made explicitly to default-frame-alist.
120(defun fringe-mode-initialize (symbol value)
121 (let* ((left-pair (assq 'left-fringe default-frame-alist))
122 (right-pair (assq 'right-fringe default-frame-alist))
123 (left (cdr left-pair))
124 (right (cdr right-pair)))
125 (if (or left-pair right-pair)
126 ;; If there's something in default-frame-alist for fringes,
127 ;; don't change it, but reflect that into the value of fringe-mode.
128 (progn
129 (setq fringe-mode (cons left right))
130 (if (equal fringe-mode '(nil . nil))
131 (setq fringe-mode nil))
132 (if (equal fringe-mode '(0 . 0))
133 (setq fringe-mode 0)))
134 ;; Otherwise impose the user-specified value of fringe-mode.
135 (custom-initialize-reset symbol value))))
136
02f4566a
SJ
137(defcustom fringe-mode nil
138 "*Specify appearance of fringes on all frames.
139This variable can be nil (the default) meaning the fringes should have
140the default width (8 pixels), it can be an integer value specifying
141the width of both left and right fringe (where 0 means no fringe), or
142a cons cell where car indicates width of left fringe and cdr indicates
143width of right fringe (where again 0 can be used to indicate no
144fringe).
145To set this variable in a Lisp program, use `set-fringe-mode' to make
146it take real effect.
147Setting the variable with a customization buffer also takes effect.
148If you only want to modify the appearance of the fringe in one frame,
feed81e9 149you can use the interactive function `set-fringe-style'."
02f4566a
SJ
150 :type '(choice (const :tag "Default width" nil)
151 (const :tag "No fringes" 0)
152 (const :tag "Only right" (0 . nil))
153 (const :tag "Only left" (nil . 0))
154 (const :tag "Half width" (5 . 5))
255866b7 155 (const :tag "Minimal" (1 . 1))
02f4566a
SJ
156 (integer :tag "Specific width")
157 (cons :tag "Different left/right sizes"
158 (integer :tag "Left width")
159 (integer :tag "Right width")))
41e1c123 160 :group 'fringe
02f4566a 161 :require 'fringe
efa0a47a 162 :initialize 'fringe-mode-initialize
02f4566a
SJ
163 :set 'set-fringe-mode-1)
164
f78a91b3
MR
165;; We just set fringe-mode, but that was the default.
166;; If it is set again, that is for real.
167(setq fringe-mode-explicit t)
168
02f4566a
SJ
169(defun fringe-query-style (&optional all-frames)
170 "Query user for fringe style.
171Returns values suitable for left-fringe and right-fringe frame parameters.
172If ALL-FRAMES, the negation of the fringe values in
173`default-frame-alist' is used when user enters the empty string.
174Otherwise the negation of the fringe value in the currently selected
175frame parameter is used."
176 (let ((mode (intern (completing-read
feed81e9
JL
177 (concat
178 "Select fringe mode for "
179 (if all-frames "all frames" "selected frame")
180 " (type ? for list): ")
02f4566a 181 '(("none") ("default") ("left-only")
19c8fe75 182 ("right-only") ("half") ("minimal"))
02f4566a
SJ
183 nil t))))
184 (cond ((eq mode 'none) 0)
185 ((eq mode 'default) nil)
186 ((eq mode 'left-only) '(nil . 0))
187 ((eq mode 'right-only) '(0 . nil))
188 ((eq mode 'half) '(5 . 5))
19c8fe75 189 ((eq mode 'minimal) '(1 . 1))
02f4566a
SJ
190 ((eq mode (intern ""))
191 (if (eq 0 (cdr (assq 'left-fringe
192 (if all-frames
193 default-frame-alist
194 (frame-parameters (selected-frame))))))
195 nil
196 0)))))
197
02f4566a 198(defun fringe-mode (&optional mode)
1c907043 199 "Set the default appearance of fringes on all frames.
af15cfe8 200
1c907043
LK
201When called interactively, query the user for MODE. Valid values
202for MODE include `none', `default', `left-only', `right-only',
203`minimal' and `half'.
af15cfe8
LK
204
205When used in a Lisp program, MODE can be a cons cell where the
206integer in car specifies the left fringe width and the integer in
207cdr specifies the right fringe width. MODE can also be a single
208integer that specifies both the left and the right fringe width.
1c907043
LK
209If a fringe width specification is nil, that means to use the
210default width (8 pixels). This command may round up the left and
211right width specifications to ensure that their sum is a multiple
212of the character width of a frame. It never rounds up a fringe
213width of 0.
af15cfe8
LK
214
215Fringe widths set by `set-window-fringes' override the default
216fringe widths set by this command. This command applies to all
217frames that exist and frames to be created in the future. If you
218want to set the default appearance of fringes on the selected
219frame only, see the command `set-fringe-style'."
02f4566a
SJ
220 (interactive (list (fringe-query-style 'all-frames)))
221 (set-fringe-mode mode))
222
02f4566a 223(defun set-fringe-style (&optional mode)
1c907043 224 "Set the default appearance of fringes on the selected frame.
af15cfe8 225
1c907043
LK
226When called interactively, query the user for MODE. Valid values
227for MODE include `none', `default', `left-only', `right-only',
228`minimal' and `half'.
af15cfe8
LK
229
230When used in a Lisp program, MODE can be a cons cell where the
231integer in car specifies the left fringe width and the integer in
232cdr specifies the right fringe width. MODE can also be a single
233integer that specifies both the left and the right fringe width.
1c907043
LK
234If a fringe width specification is nil, that means to use the
235default width (8 pixels). This command may round up the left and
236right width specifications to ensure that their sum is a multiple
237of the character width of a frame. It never rounds up a fringe
238width of 0.
af15cfe8
LK
239
240Fringe widths set by `set-window-fringes' override the default
241fringe widths set by this command. If you want to set the
242default appearance of fringes on all frames, see the command
243`fringe-mode'."
02f4566a
SJ
244 (interactive (list (fringe-query-style)))
245 (modify-frame-parameters
246 (selected-frame)
247 (list (cons 'left-fringe (if (consp mode) (car mode) mode))
248 (cons 'right-fringe (if (consp mode) (cdr mode) mode)))))
249
9fd76d04
MY
250(defsubst fringe-columns (side &optional real)
251 "Return the width, measured in columns, of the fringe area on SIDE.
252If optional argument REAL is non-nil, return a real floating point
253number instead of a rounded integer value.
254SIDE must be the symbol `left' or `right'."
255 (funcall (if real '/ 'ceiling)
256 (or (funcall (if (eq side 'left) 'car 'cadr)
257 (window-fringes))
258 0)
259 (float (frame-char-width))))
822c2a0a 260
02f4566a
SJ
261(provide 'fringe)
262
cbee283d 263;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d
02f4566a 264;;; fringe.el ends here