Add 2012 to FSF copyright years for Emacs files (do not merge to trunk)
[bpt/emacs.git] / lisp / fringe.el
CommitLineData
fdf483c9 1;;; fringe.el --- fringe setup and control -*- coding: utf-8 -*-
02f4566a 2
ae940284 3;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008,
49f70d46 4;; 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
02f4566a
SJ
5
6;; Author: Simon Josefsson <simon@josefsson.org>
7;; Maintainer: FSF
8;; Keywords: frames
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
33;; Bader, Eli Zaretski, Richard Stallman, Pavel Janík and others which
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
02f4566a
SJ
99(defun set-fringe-mode-1 (ignore value)
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
02f4566a 138(defcustom fringe-mode nil
9201cc28 139 "Specify appearance of fringes on all frames.
02f4566a
SJ
140This variable can be nil (the default) meaning the fringes should have
141the default width (8 pixels), it can be an integer value specifying
142the width of both left and right fringe (where 0 means no fringe), or
143a cons cell where car indicates width of left fringe and cdr indicates
144width of right fringe (where again 0 can be used to indicate no
145fringe).
146To set this variable in a Lisp program, use `set-fringe-mode' to make
147it take real effect.
148Setting the variable with a customization buffer also takes effect.
149If you only want to modify the appearance of the fringe in one frame,
feed81e9 150you can use the interactive function `set-fringe-style'."
02f4566a
SJ
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))
255866b7 156 (const :tag "Minimal" (1 . 1))
02f4566a
SJ
157 (integer :tag "Specific width")
158 (cons :tag "Different left/right sizes"
159 (integer :tag "Left width")
160 (integer :tag "Right width")))
41e1c123 161 :group 'fringe
02f4566a 162 :require 'fringe
efa0a47a 163 :initialize 'fringe-mode-initialize
02f4566a
SJ
164 :set 'set-fringe-mode-1)
165
f78a91b3
MR
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)
169
02f4566a
SJ
170(defun fringe-query-style (&optional all-frames)
171 "Query user for fringe style.
172Returns values suitable for left-fringe and right-fringe frame parameters.
173If ALL-FRAMES, the negation of the fringe values in
174`default-frame-alist' is used when user enters the empty string.
175Otherwise the negation of the fringe value in the currently selected
176frame parameter is used."
177 (let ((mode (intern (completing-read
feed81e9
JL
178 (concat
179 "Select fringe mode for "
180 (if all-frames "all frames" "selected frame")
181 " (type ? for list): ")
02f4566a 182 '(("none") ("default") ("left-only")
19c8fe75 183 ("right-only") ("half") ("minimal"))
02f4566a
SJ
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))
19c8fe75 190 ((eq mode 'minimal) '(1 . 1))
02f4566a
SJ
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))))))
196 nil
197 0)))))
198
02f4566a 199(defun fringe-mode (&optional mode)
1c907043 200 "Set the default appearance of fringes on all frames.
af15cfe8 201
1c907043
LK
202When called interactively, query the user for MODE. Valid values
203for MODE include `none', `default', `left-only', `right-only',
204`minimal' and `half'.
af15cfe8
LK
205
206When used in a Lisp program, MODE can be a cons cell where the
207integer in car specifies the left fringe width and the integer in
208cdr specifies the right fringe width. MODE can also be a single
209integer that specifies both the left and the right fringe width.
1c907043
LK
210If a fringe width specification is nil, that means to use the
211default width (8 pixels). This command may round up the left and
212right width specifications to ensure that their sum is a multiple
213of the character width of a frame. It never rounds up a fringe
214width of 0.
af15cfe8
LK
215
216Fringe widths set by `set-window-fringes' override the default
217fringe widths set by this command. This command applies to all
218frames that exist and frames to be created in the future. If you
219want to set the default appearance of fringes on the selected
220frame only, see the command `set-fringe-style'."
02f4566a
SJ
221 (interactive (list (fringe-query-style 'all-frames)))
222 (set-fringe-mode mode))
223
02f4566a 224(defun set-fringe-style (&optional mode)
1c907043 225 "Set the default appearance of fringes on the selected frame.
af15cfe8 226
1c907043
LK
227When called interactively, query the user for MODE. Valid values
228for MODE include `none', `default', `left-only', `right-only',
229`minimal' and `half'.
af15cfe8
LK
230
231When used in a Lisp program, MODE can be a cons cell where the
232integer in car specifies the left fringe width and the integer in
233cdr specifies the right fringe width. MODE can also be a single
234integer that specifies both the left and the right fringe width.
1c907043
LK
235If a fringe width specification is nil, that means to use the
236default width (8 pixels). This command may round up the left and
237right width specifications to ensure that their sum is a multiple
238of the character width of a frame. It never rounds up a fringe
239width of 0.
af15cfe8
LK
240
241Fringe widths set by `set-window-fringes' override the default
242fringe widths set by this command. If you want to set the
243default appearance of fringes on all frames, see the command
244`fringe-mode'."
02f4566a
SJ
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)))))
250
9fd76d04
MY
251(defsubst fringe-columns (side &optional real)
252 "Return the width, measured in columns, of the fringe area on SIDE.
253If optional argument REAL is non-nil, return a real floating point
254number instead of a rounded integer value.
255SIDE must be the symbol `left' or `right'."
256 (funcall (if real '/ 'ceiling)
257 (or (funcall (if (eq side 'left) 'car 'cadr)
258 (window-fringes))
259 0)
260 (float (frame-char-width))))
822c2a0a 261
02f4566a
SJ
262(provide 'fringe)
263
cbee283d 264;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d
02f4566a 265;;; fringe.el ends here