* emacs-lisp/bytecomp.el (byte-recompile-directory): Ignore dir-locals-file.
[emacs.git] / lisp / fringe.el
blob600ef7ca1e1c4f38880a458b5751003ea98e66a7
1 ;;; fringe.el --- fringe setup and control -*- coding: utf-8 -*-
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 ;; 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Simon Josefsson <simon@josefsson.org>
7 ;; Maintainer: FSF
8 ;; Keywords: frames
9 ;; Package: emacs
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
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.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Commentary:
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.
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.
37 ;;; Code:
39 (defgroup fringe nil
40 "Window fringes."
41 :version "22.1"
42 :group 'frames)
44 ;; Define the built-in fringe bitmaps and setup default mappings
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))))
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)))
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))))
87 (defmacro fringe-bitmap-p (symbol)
88 "Return non-nil if SYMBOL is a fringe bitmap."
89 `(get ,symbol 'fringe))
92 ;; Control presence of fringes
94 (defvar fringe-mode)
96 (defvar fringe-mode-explicit nil
97 "Non-nil means `set-fringe-mode' should really do something.
98 This is nil while loading `fringe.el', and t afterward.")
100 (defun set-fringe-mode-1 (ignore value)
101 "Call `set-fringe-mode' with VALUE.
102 See `fringe-mode' for valid values and their effect.
103 This is usually invoked when setting `fringe-mode' via customize."
104 (set-fringe-mode value))
106 (defun set-fringe-mode (value)
107 "Set `fringe-mode' to VALUE and put the new value into effect.
108 See `fringe-mode' for possible values and their effect."
109 (setq fringe-mode value)
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))))))
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))))
139 (defcustom fringe-mode nil
140 "Specify appearance of fringes on all frames.
141 This variable can be nil (the default) meaning the fringes should have
142 the default width (8 pixels), it can be an integer value specifying
143 the width of both left and right fringe (where 0 means no fringe), or
144 a cons cell where car indicates width of left fringe and cdr indicates
145 width of right fringe (where again 0 can be used to indicate no
146 fringe).
147 To set this variable in a Lisp program, use `set-fringe-mode' to make
148 it take real effect.
149 Setting the variable with a customization buffer also takes effect.
150 If you only want to modify the appearance of the fringe in one frame,
151 you can use the interactive function `set-fringe-style'."
152 :type '(choice (const :tag "Default width" nil)
153 (const :tag "No fringes" 0)
154 (const :tag "Only right" (0 . nil))
155 (const :tag "Only left" (nil . 0))
156 (const :tag "Half width" (5 . 5))
157 (const :tag "Minimal" (1 . 1))
158 (integer :tag "Specific width")
159 (cons :tag "Different left/right sizes"
160 (integer :tag "Left width")
161 (integer :tag "Right width")))
162 :group 'fringe
163 :require 'fringe
164 :initialize 'fringe-mode-initialize
165 :set 'set-fringe-mode-1)
167 ;; We just set fringe-mode, but that was the default.
168 ;; If it is set again, that is for real.
169 (setq fringe-mode-explicit t)
171 (defun fringe-query-style (&optional all-frames)
172 "Query user for fringe style.
173 Returns values suitable for left-fringe and right-fringe frame parameters.
174 If ALL-FRAMES, the negation of the fringe values in
175 `default-frame-alist' is used when user enters the empty string.
176 Otherwise the negation of the fringe value in the currently selected
177 frame parameter is used."
178 (let ((mode (intern (completing-read
179 (concat
180 "Select fringe mode for "
181 (if all-frames "all frames" "selected frame")
182 " (type ? for list): ")
183 '(("none") ("default") ("left-only")
184 ("right-only") ("half") ("minimal"))
185 nil t))))
186 (cond ((eq mode 'none) 0)
187 ((eq mode 'default) nil)
188 ((eq mode 'left-only) '(nil . 0))
189 ((eq mode 'right-only) '(0 . nil))
190 ((eq mode 'half) '(5 . 5))
191 ((eq mode 'minimal) '(1 . 1))
192 ((eq mode (intern ""))
193 (if (eq 0 (cdr (assq 'left-fringe
194 (if all-frames
195 default-frame-alist
196 (frame-parameters (selected-frame))))))
198 0)))))
200 (defun fringe-mode (&optional mode)
201 "Set the default appearance of fringes on all frames.
203 When called interactively, query the user for MODE. Valid values
204 for MODE include `none', `default', `left-only', `right-only',
205 `minimal' and `half'.
207 When used in a Lisp program, MODE can be a cons cell where the
208 integer in car specifies the left fringe width and the integer in
209 cdr specifies the right fringe width. MODE can also be a single
210 integer that specifies both the left and the right fringe width.
211 If a fringe width specification is nil, that means to use the
212 default width (8 pixels). This command may round up the left and
213 right width specifications to ensure that their sum is a multiple
214 of the character width of a frame. It never rounds up a fringe
215 width of 0.
217 Fringe widths set by `set-window-fringes' override the default
218 fringe widths set by this command. This command applies to all
219 frames that exist and frames to be created in the future. If you
220 want to set the default appearance of fringes on the selected
221 frame only, see the command `set-fringe-style'."
222 (interactive (list (fringe-query-style 'all-frames)))
223 (set-fringe-mode mode))
225 (defun set-fringe-style (&optional mode)
226 "Set the default appearance of fringes on the selected frame.
228 When called interactively, query the user for MODE. Valid values
229 for MODE include `none', `default', `left-only', `right-only',
230 `minimal' and `half'.
232 When used in a Lisp program, MODE can be a cons cell where the
233 integer in car specifies the left fringe width and the integer in
234 cdr specifies the right fringe width. MODE can also be a single
235 integer that specifies both the left and the right fringe width.
236 If a fringe width specification is nil, that means to use the
237 default width (8 pixels). This command may round up the left and
238 right width specifications to ensure that their sum is a multiple
239 of the character width of a frame. It never rounds up a fringe
240 width of 0.
242 Fringe widths set by `set-window-fringes' override the default
243 fringe widths set by this command. If you want to set the
244 default appearance of fringes on all frames, see the command
245 `fringe-mode'."
246 (interactive (list (fringe-query-style)))
247 (modify-frame-parameters
248 (selected-frame)
249 (list (cons 'left-fringe (if (consp mode) (car mode) mode))
250 (cons 'right-fringe (if (consp mode) (cdr mode) mode)))))
252 (defsubst fringe-columns (side &optional real)
253 "Return the width, measured in columns, of the fringe area on SIDE.
254 If optional argument REAL is non-nil, return a real floating point
255 number instead of a rounded integer value.
256 SIDE must be the symbol `left' or `right'."
257 (funcall (if real '/ 'ceiling)
258 (or (funcall (if (eq side 'left) 'car 'cadr)
259 (window-fringes))
261 (float (frame-char-width))))
263 (provide 'fringe)
265 ;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d
266 ;;; fringe.el ends here