annotate lisp/fringe.el @ 45493:6d49cede6000

Initial version.
author Simon Josefsson <jas@extundo.com>
date Fri, 24 May 2002 09:52:53 +0000
parents
children 6b848a738ec6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45493
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
1 ;;; fringe.el --- change fringes appearance in various ways
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
2
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
3 ;; Copyright (C) 2002 Free Software Foundation, Inc.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
4
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
5 ;; Author: Simon Josefsson <simon@josefsson.org>
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
6 ;; Maintainer: FSF
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
7 ;; Keywords: frames
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
8
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
10
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
14 ;; any later version.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
15
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
19 ;; GNU General Public License for more details.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
20
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
25
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
26 ;;; Commentary:
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
27
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
28 ;; This file contains helpful functions for customizing the appearance
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
29 ;; of the fringe.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
30
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
31 ;; The code is influenced by scroll-bar.el and avoid.el. The author
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
32 ;; gratefully acknowledge comments and suggestions made by Miles
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
33 ;; Bader, Eli Zaretski, Richard Stallman, Pavel Janík and others which
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
34 ;; improved this package.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
35
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
36 ;;; Code:
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
37
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
38 (defvar fringe-mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
39
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
40 (defun set-fringe-mode-1 (ignore value)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
41 "Call `set-fringe-mode' with VALUE.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
42 See `fringe-mode' for valid values and their effect.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
43 This is usually invoked when setting `fringe-mode' via customize."
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
44 (set-fringe-mode value))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
45
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
46 (defun set-fringe-mode (value)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
47 "Set `fringe-mode' to VALUE and put the new value into effect.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
48 See `fringe-mode' for possible values and their effect."
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
49 (setq fringe-mode value)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
50
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
51 ;; Apply it to default-frame-alist.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
52 (let ((parameter (assq 'left-fringe default-frame-alist)))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
53 (if (consp parameter)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
54 (setcdr parameter fringe-mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
55 (setq default-frame-alist
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
56 (cons (cons 'left-fringe (if (consp fringe-mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
57 (car fringe-mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
58 fringe-mode))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
59 default-frame-alist))))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
60 (let ((parameter (assq 'right-fringe default-frame-alist)))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
61 (if (consp parameter)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
62 (setcdr parameter fringe-mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
63 (setq default-frame-alist
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
64 (cons (cons 'right-fringe (if (consp fringe-mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
65 (cdr fringe-mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
66 fringe-mode))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
67 default-frame-alist))))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
68
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
69 ;; Apply it to existing frames.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
70 (let ((frames (frame-list)))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
71 (while frames
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
72 (modify-frame-parameters
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
73 (car frames)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
74 (list (cons 'left-fringe (if (consp fringe-mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
75 (car fringe-mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
76 fringe-mode))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
77 (cons 'right-fringe (if (consp fringe-mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
78 (cdr fringe-mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
79 fringe-mode))))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
80 (setq frames (cdr frames)))))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
81
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
82 (defcustom fringe-mode nil
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
83 "*Specify appearance of fringes on all frames.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
84 This variable can be nil (the default) meaning the fringes should have
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
85 the default width (8 pixels), it can be an integer value specifying
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
86 the width of both left and right fringe (where 0 means no fringe), or
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
87 a cons cell where car indicates width of left fringe and cdr indicates
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
88 width of right fringe (where again 0 can be used to indicate no
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
89 fringe).
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
90 To set this variable in a Lisp program, use `set-fringe-mode' to make
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
91 it take real effect.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
92 Setting the variable with a customization buffer also takes effect.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
93 If you only want to modify the appearance of the fringe in one frame,
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
94 you can use the interactive function `toggle-fringe'"
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
95 :type '(choice (const :tag "Default width" nil)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
96 (const :tag "No fringes" 0)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
97 (const :tag "Only right" (0 . nil))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
98 (const :tag "Only left" (nil . 0))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
99 (const :tag "Half width" (5 . 5))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
100 (integer :tag "Specific width")
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
101 (cons :tag "Different left/right sizes"
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
102 (integer :tag "Left width")
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
103 (integer :tag "Right width")))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
104 :group 'frames
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
105 :require 'fringe
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
106 :set 'set-fringe-mode-1)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
107
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
108 (defun fringe-query-style (&optional all-frames)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
109 "Query user for fringe style.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
110 Returns values suitable for left-fringe and right-fringe frame parameters.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
111 If ALL-FRAMES, the negation of the fringe values in
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
112 `default-frame-alist' is used when user enters the empty string.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
113 Otherwise the negation of the fringe value in the currently selected
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
114 frame parameter is used."
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
115 (let ((mode (intern (completing-read
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
116 "Select fringe mode for all frames (SPACE for list): "
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
117 '(("none") ("default") ("left-only")
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
118 ("right-only") ("half"))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
119 nil t))))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
120 (cond ((eq mode 'none) 0)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
121 ((eq mode 'default) nil)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
122 ((eq mode 'left-only) '(nil . 0))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
123 ((eq mode 'right-only) '(0 . nil))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
124 ((eq mode 'half) '(5 . 5))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
125 ((eq mode (intern ""))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
126 (if (eq 0 (cdr (assq 'left-fringe
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
127 (if all-frames
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
128 default-frame-alist
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
129 (frame-parameters (selected-frame))))))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
130 nil
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
131 0)))))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
132
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
133 ;;;###autoload
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
134 (defun fringe-mode (&optional mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
135 "Toggle appearance of fringes on all frames.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
136 Valid values for MODE include `none', `default', `left-only',
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
137 `right-only' and `half'. MODE can also be a cons cell where the
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
138 integer in car will be used as left fringe width and the integer in
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
139 cdr will be used as right fringe width. If MODE is not specified, the
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
140 user is queried.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
141 It applies to all frames that exist and frames to be created in the
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
142 future.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
143 If you want to set appearance of fringes on the selected frame only,
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
144 see `set-fringe-style'."
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
145 (interactive (list (fringe-query-style 'all-frames)))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
146 (set-fringe-mode mode))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
147
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
148 ;;;###autoload
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
149 (defun set-fringe-style (&optional mode)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
150 "Set appearance of fringes on selected frame.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
151 Valid values for MODE include `none', `default', `left-only',
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
152 `right-only' and `half'. MODE can also be a cons cell where the
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
153 integer in car will be used as left fringe width and the integer in
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
154 cdr will be used as right fringe width. If MODE is not specified, the
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
155 user is queried.
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
156 If you want to set appearance of fringes on all frames, see `fringe-mode'."
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
157 (interactive (list (fringe-query-style)))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
158 (modify-frame-parameters
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
159 (selected-frame)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
160 (list (cons 'left-fringe (if (consp mode) (car mode) mode))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
161 (cons 'right-fringe (if (consp mode) (cdr mode) mode)))))
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
162
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
163 (provide 'fringe)
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
164
6d49cede6000 Initial version.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
165 ;;; fringe.el ends here