(fringe-mode): Use active voice in docstring.
[bpt/emacs.git] / lisp / fringe.el
1 ;;; fringe.el --- change fringes appearance in various ways
2
3 ;; Copyright (C) 2002, 2003 Free Software Foundation, Inc.
4
5 ;; Author: Simon Josefsson <simon@josefsson.org>
6 ;; Maintainer: FSF
7 ;; Keywords: frames
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
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
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; This file contains helpful functions for customizing the appearance
29 ;; of the fringe.
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
38 (defvar fringe-mode)
39
40 (defun set-fringe-mode-1 (ignore value)
41 "Call `set-fringe-mode' with VALUE.
42 See `fringe-mode' for valid values and their effect.
43 This is usually invoked when setting `fringe-mode' via customize."
44 (set-fringe-mode value))
45
46 (defun set-fringe-mode (value)
47 "Set `fringe-mode' to VALUE and put the new value into effect.
48 See `fringe-mode' for possible values and their effect."
49 (setq fringe-mode value)
50
51 ;; Apply it to default-frame-alist.
52 (let ((parameter (assq 'left-fringe default-frame-alist)))
53 (if (consp parameter)
54 (setcdr parameter (if (consp fringe-mode)
55 (car fringe-mode)
56 fringe-mode))
57 (setq default-frame-alist
58 (cons (cons 'left-fringe (if (consp fringe-mode)
59 (car fringe-mode)
60 fringe-mode))
61 default-frame-alist))))
62 (let ((parameter (assq 'right-fringe default-frame-alist)))
63 (if (consp parameter)
64 (setcdr parameter (if (consp fringe-mode)
65 (cdr fringe-mode)
66 fringe-mode))
67 (setq default-frame-alist
68 (cons (cons 'right-fringe (if (consp fringe-mode)
69 (cdr fringe-mode)
70 fringe-mode))
71 default-frame-alist))))
72
73 ;; Apply it to existing frames.
74 (let ((frames (frame-list)))
75 (while frames
76 (modify-frame-parameters
77 (car frames)
78 (list (cons 'left-fringe (if (consp fringe-mode)
79 (car fringe-mode)
80 fringe-mode))
81 (cons 'right-fringe (if (consp fringe-mode)
82 (cdr fringe-mode)
83 fringe-mode))))
84 (setq frames (cdr frames)))))
85
86 ;;;###autoload
87 (defcustom fringe-mode nil
88 "*Specify appearance of fringes on all frames.
89 This variable can be nil (the default) meaning the fringes should have
90 the default width (8 pixels), it can be an integer value specifying
91 the width of both left and right fringe (where 0 means no fringe), or
92 a cons cell where car indicates width of left fringe and cdr indicates
93 width of right fringe (where again 0 can be used to indicate no
94 fringe).
95 To set this variable in a Lisp program, use `set-fringe-mode' to make
96 it take real effect.
97 Setting the variable with a customization buffer also takes effect.
98 If you only want to modify the appearance of the fringe in one frame,
99 you can use the interactive function `toggle-fringe'"
100 :type '(choice (const :tag "Default width" nil)
101 (const :tag "No fringes" 0)
102 (const :tag "Only right" (0 . nil))
103 (const :tag "Only left" (nil . 0))
104 (const :tag "Half width" (5 . 5))
105 (const :tag "Minimal" (1 . 1))
106 (integer :tag "Specific width")
107 (cons :tag "Different left/right sizes"
108 (integer :tag "Left width")
109 (integer :tag "Right width")))
110 :group 'frames
111 :require 'fringe
112 :set 'set-fringe-mode-1)
113
114 (defun fringe-query-style (&optional all-frames)
115 "Query user for fringe style.
116 Returns values suitable for left-fringe and right-fringe frame parameters.
117 If ALL-FRAMES, the negation of the fringe values in
118 `default-frame-alist' is used when user enters the empty string.
119 Otherwise the negation of the fringe value in the currently selected
120 frame parameter is used."
121 (let ((mode (intern (completing-read
122 "Select fringe mode for all frames (SPACE for list): "
123 '(("none") ("default") ("left-only")
124 ("right-only") ("half") ("minimal"))
125 nil t))))
126 (cond ((eq mode 'none) 0)
127 ((eq mode 'default) nil)
128 ((eq mode 'left-only) '(nil . 0))
129 ((eq mode 'right-only) '(0 . nil))
130 ((eq mode 'half) '(5 . 5))
131 ((eq mode 'minimal) '(1 . 1))
132 ((eq mode (intern ""))
133 (if (eq 0 (cdr (assq 'left-fringe
134 (if all-frames
135 default-frame-alist
136 (frame-parameters (selected-frame))))))
137 nil
138 0)))))
139
140 ;;;###autoload
141 (defun fringe-mode (&optional mode)
142 "Set the default appearance of fringes on all frames.
143
144 When called interactively, query the user for MODE. Valid values
145 for MODE include `none', `default', `left-only', `right-only',
146 `minimal' and `half'.
147
148 When used in a Lisp program, MODE can be a cons cell where the
149 integer in car specifies the left fringe width and the integer in
150 cdr specifies the right fringe width. MODE can also be a single
151 integer that specifies both the left and the right fringe width.
152 If a fringe width specification is nil, that means to use the
153 default width (8 pixels). This command may round up the left and
154 right width specifications to ensure that their sum is a multiple
155 of the character width of a frame. It never rounds up a fringe
156 width of 0.
157
158 Fringe widths set by `set-window-fringes' override the default
159 fringe widths set by this command. This command applies to all
160 frames that exist and frames to be created in the future. If you
161 want to set the default appearance of fringes on the selected
162 frame only, see the command `set-fringe-style'."
163 (interactive (list (fringe-query-style 'all-frames)))
164 (set-fringe-mode mode))
165
166 ;;;###autoload
167 (defun set-fringe-style (&optional mode)
168 "Set the default appearance of fringes on the selected frame.
169
170 When called interactively, query the user for MODE. Valid values
171 for MODE include `none', `default', `left-only', `right-only',
172 `minimal' and `half'.
173
174 When used in a Lisp program, MODE can be a cons cell where the
175 integer in car specifies the left fringe width and the integer in
176 cdr specifies the right fringe width. MODE can also be a single
177 integer that specifies both the left and the right fringe width.
178 If a fringe width specification is nil, that means to use the
179 default width (8 pixels). This command may round up the left and
180 right width specifications to ensure that their sum is a multiple
181 of the character width of a frame. It never rounds up a fringe
182 width of 0.
183
184 Fringe widths set by `set-window-fringes' override the default
185 fringe widths set by this command. If you want to set the
186 default appearance of fringes on all frames, see the command
187 `fringe-mode'."
188 (interactive (list (fringe-query-style)))
189 (modify-frame-parameters
190 (selected-frame)
191 (list (cons 'left-fringe (if (consp mode) (car mode) mode))
192 (cons 'right-fringe (if (consp mode) (cdr mode) mode)))))
193
194 (provide 'fringe)
195
196 ;;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d
197 ;;; fringe.el ends here