Commit | Line | Data |
---|---|---|
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. | |
98 | This 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. | |
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)) | |
105 | ||
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) | |
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 | ||
02f4566a | 139 | (defcustom fringe-mode nil |
9201cc28 | 140 | "Specify appearance of fringes on all frames. |
02f4566a SJ |
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). | |
71b961e8 EZ |
147 | Note that the actual width may be rounded up to ensure that the sum of |
148 | the width of the left and right fringes is a multiple of the frame's | |
149 | character width. However, a fringe width of 0 is never rounded. | |
02f4566a SJ |
150 | To set this variable in a Lisp program, use `set-fringe-mode' to make |
151 | it take real effect. | |
152 | Setting the variable with a customization buffer also takes effect. | |
153 | If you only want to modify the appearance of the fringe in one frame, | |
feed81e9 | 154 | you can use the interactive function `set-fringe-style'." |
02f4566a SJ |
155 | :type '(choice (const :tag "Default width" nil) |
156 | (const :tag "No fringes" 0) | |
157 | (const :tag "Only right" (0 . nil)) | |
158 | (const :tag "Only left" (nil . 0)) | |
a67597d6 | 159 | (const :tag "Half width" (4 . 4)) |
255866b7 | 160 | (const :tag "Minimal" (1 . 1)) |
02f4566a SJ |
161 | (integer :tag "Specific width") |
162 | (cons :tag "Different left/right sizes" | |
163 | (integer :tag "Left width") | |
164 | (integer :tag "Right width"))) | |
41e1c123 | 165 | :group 'fringe |
02f4566a | 166 | :require 'fringe |
efa0a47a | 167 | :initialize 'fringe-mode-initialize |
02f4566a SJ |
168 | :set 'set-fringe-mode-1) |
169 | ||
f78a91b3 MR |
170 | ;; We just set fringe-mode, but that was the default. |
171 | ;; If it is set again, that is for real. | |
172 | (setq fringe-mode-explicit t) | |
173 | ||
02f4566a SJ |
174 | (defun fringe-query-style (&optional all-frames) |
175 | "Query user for fringe style. | |
176 | Returns values suitable for left-fringe and right-fringe frame parameters. | |
177 | If ALL-FRAMES, the negation of the fringe values in | |
178 | `default-frame-alist' is used when user enters the empty string. | |
179 | Otherwise the negation of the fringe value in the currently selected | |
180 | frame parameter is used." | |
181 | (let ((mode (intern (completing-read | |
feed81e9 JL |
182 | (concat |
183 | "Select fringe mode for " | |
184 | (if all-frames "all frames" "selected frame") | |
185 | " (type ? for list): ") | |
02f4566a | 186 | '(("none") ("default") ("left-only") |
19c8fe75 | 187 | ("right-only") ("half") ("minimal")) |
02f4566a SJ |
188 | nil t)))) |
189 | (cond ((eq mode 'none) 0) | |
190 | ((eq mode 'default) nil) | |
191 | ((eq mode 'left-only) '(nil . 0)) | |
192 | ((eq mode 'right-only) '(0 . nil)) | |
a67597d6 | 193 | ((eq mode 'half) '(4 . 4)) |
19c8fe75 | 194 | ((eq mode 'minimal) '(1 . 1)) |
02f4566a SJ |
195 | ((eq mode (intern "")) |
196 | (if (eq 0 (cdr (assq 'left-fringe | |
197 | (if all-frames | |
198 | default-frame-alist | |
199 | (frame-parameters (selected-frame)))))) | |
200 | nil | |
201 | 0))))) | |
202 | ||
02f4566a | 203 | (defun fringe-mode (&optional mode) |
1c907043 | 204 | "Set the default appearance of fringes on all frames. |
af15cfe8 | 205 | |
1c907043 LK |
206 | When called interactively, query the user for MODE. Valid values |
207 | for MODE include `none', `default', `left-only', `right-only', | |
208 | `minimal' and `half'. | |
af15cfe8 LK |
209 | |
210 | When used in a Lisp program, MODE can be a cons cell where the | |
211 | integer in car specifies the left fringe width and the integer in | |
212 | cdr specifies the right fringe width. MODE can also be a single | |
213 | integer that specifies both the left and the right fringe width. | |
1c907043 LK |
214 | If a fringe width specification is nil, that means to use the |
215 | default width (8 pixels). This command may round up the left and | |
216 | right width specifications to ensure that their sum is a multiple | |
217 | of the character width of a frame. It never rounds up a fringe | |
218 | width of 0. | |
af15cfe8 LK |
219 | |
220 | Fringe widths set by `set-window-fringes' override the default | |
221 | fringe widths set by this command. This command applies to all | |
222 | frames that exist and frames to be created in the future. If you | |
223 | want to set the default appearance of fringes on the selected | |
224 | frame only, see the command `set-fringe-style'." | |
02f4566a SJ |
225 | (interactive (list (fringe-query-style 'all-frames))) |
226 | (set-fringe-mode mode)) | |
227 | ||
02f4566a | 228 | (defun set-fringe-style (&optional mode) |
1c907043 | 229 | "Set the default appearance of fringes on the selected frame. |
af15cfe8 | 230 | |
1c907043 LK |
231 | When called interactively, query the user for MODE. Valid values |
232 | for MODE include `none', `default', `left-only', `right-only', | |
233 | `minimal' and `half'. | |
af15cfe8 LK |
234 | |
235 | When used in a Lisp program, MODE can be a cons cell where the | |
236 | integer in car specifies the left fringe width and the integer in | |
237 | cdr specifies the right fringe width. MODE can also be a single | |
238 | integer that specifies both the left and the right fringe width. | |
1c907043 LK |
239 | If a fringe width specification is nil, that means to use the |
240 | default width (8 pixels). This command may round up the left and | |
241 | right width specifications to ensure that their sum is a multiple | |
242 | of the character width of a frame. It never rounds up a fringe | |
243 | width of 0. | |
af15cfe8 LK |
244 | |
245 | Fringe widths set by `set-window-fringes' override the default | |
246 | fringe widths set by this command. If you want to set the | |
247 | default appearance of fringes on all frames, see the command | |
248 | `fringe-mode'." | |
02f4566a SJ |
249 | (interactive (list (fringe-query-style))) |
250 | (modify-frame-parameters | |
251 | (selected-frame) | |
252 | (list (cons 'left-fringe (if (consp mode) (car mode) mode)) | |
253 | (cons 'right-fringe (if (consp mode) (cdr mode) mode))))) | |
254 | ||
9fd76d04 MY |
255 | (defsubst fringe-columns (side &optional real) |
256 | "Return the width, measured in columns, of the fringe area on SIDE. | |
257 | If optional argument REAL is non-nil, return a real floating point | |
258 | number instead of a rounded integer value. | |
259 | SIDE must be the symbol `left' or `right'." | |
260 | (funcall (if real '/ 'ceiling) | |
261 | (or (funcall (if (eq side 'left) 'car 'cadr) | |
262 | (window-fringes)) | |
263 | 0) | |
264 | (float (frame-char-width)))) | |
822c2a0a | 265 | |
02f4566a SJ |
266 | (provide 'fringe) |
267 | ||
cbee283d | 268 | ;; arch-tag: 6611ef60-0869-47ed-8b93-587ee7d3ff5d |
02f4566a | 269 | ;;; fringe.el ends here |