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