comparison lispref/text.texi @ 12067:73dc8205d259

*** empty log message ***
author Karl Heuer <kwzh@gnu.org>
date Mon, 05 Jun 1995 12:23:13 +0000
parents 4cc0a5e1bdac
children a6eb5f12b0f3
comparison
equal deleted inserted replaced
12066:b9b0b3f96dc2 12067:73dc8205d259
154 154
155 It is not necessary for @var{start} to be less than @var{end}; the 155 It is not necessary for @var{start} to be less than @var{end}; the
156 arguments can be given in either order. But most often the smaller 156 arguments can be given in either order. But most often the smaller
157 argument is written first. 157 argument is written first.
158 158
159 If the text being copied has any text properties, these are copied into
160 the string along with the characters they belong to. @xref{Text
161 Properties}. However, overlays (@pxref{Overlays}) in the buffer and
162 their properties are ignored, not copied.
163
159 @example 164 @example
160 @group 165 @group
161 ---------- Buffer: foo ---------- 166 ---------- Buffer: foo ----------
162 This is the contents of buffer foo 167 This is the contents of buffer foo
163 168
174 " 179 "
175 @end group 180 @end group
176 @end example 181 @end example
177 @end defun 182 @end defun
178 183
184 @defun buffer-substring-without-properties start end
185 This is like @code{buffer-substring}, except that it does not copy text
186 properties, just the characters themselves. @xref{Text Properties}.
187 Here's an example of using this function to get a word to look up in an
188 alist:
189
190 @example
191 (setq flammable
192 (assoc (buffer-substring start end)
193 '(("wood" . t) ("paper" . t)
194 ("steel" . nil) ("asbestos" . nil))))
195 @end example
196
197 If this were written using @code{buffer-substring} instead, it would not
198 work reliably; any text properties that happened to be in the word
199 copied from the buffer would make the comparisons fail.
200 @end defun
201
179 @defun buffer-string 202 @defun buffer-string
180 This function returns the contents of the accessible portion of the 203 This function returns the contents of the accessible portion of the
181 current buffer as a string. This is the portion between 204 current buffer as a string. This is the portion between
182 @code{(point-min)} and @code{(point-max)} (@pxref{Narrowing}). 205 @code{(point-min)} and @code{(point-max)} (@pxref{Narrowing}).
183 206
341 is the most frequently called function in Emacs, but programs rarely use 364 is the most frequently called function in Emacs, but programs rarely use
342 it except to install it on a keymap. 365 it except to install it on a keymap.
343 366
344 In an interactive call, @var{count} is the numeric prefix argument. 367 In an interactive call, @var{count} is the numeric prefix argument.
345 368
346 This function calls @code{auto-fill-function} if the current column number 369 This command calls @code{auto-fill-function} whenever that is
347 is greater than the value of @code{fill-column} and the character 370 non-@code{nil} and the character inserted is a space or a newline
348 inserted is a space (@pxref{Auto Filling}). 371 (@pxref{Auto Filling}).
349 372
350 @c Cross refs reworded to prevent overfull hbox. --rjc 15mar92 373 @c Cross refs reworded to prevent overfull hbox. --rjc 15mar92
351 This function performs abbrev expansion if Abbrev mode is enabled and 374 This command performs abbrev expansion if Abbrev mode is enabled and
352 the inserted character does not have word-constituent 375 the inserted character does not have word-constituent
353 syntax. (@xref{Abbrevs}, and @ref{Syntax Class Table}.) 376 syntax. (@xref{Abbrevs}, and @ref{Syntax Class Table}.)
354 377
355 This function is also responsible for calling 378 This is also responsible for calling @code{blink-paren-function} when
356 @code{blink-paren-function} when the inserted character has close 379 the inserted character has close parenthesis syntax (@pxref{Blinking}).
357 parenthesis syntax (@pxref{Blinking}).
358 @end deffn 380 @end deffn
359 381
360 @deffn Command newline &optional number-of-newlines 382 @deffn Command newline &optional number-of-newlines
361 This command inserts newlines into the current buffer before point. 383 This command inserts newlines into the current buffer before point.
362 If @var{number-of-newlines} is supplied, that many newline characters 384 If @var{number-of-newlines} is supplied, that many newline characters
707 @deffn Command copy-region-as-kill start end 729 @deffn Command copy-region-as-kill start end
708 This command saves the region defined by @var{start} and @var{end} on 730 This command saves the region defined by @var{start} and @var{end} on
709 the kill ring, but does not delete the text from the buffer. It returns 731 the kill ring, but does not delete the text from the buffer. It returns
710 @code{nil}. It also indicates the extent of the text copied by moving 732 @code{nil}. It also indicates the extent of the text copied by moving
711 the cursor momentarily, or by displaying a message in the echo area. 733 the cursor momentarily, or by displaying a message in the echo area.
734
735 The command does not set @code{this-command} to @code{kill-region}, so a
736 subsequent kill command does not append to the same kill ring entry.
712 737
713 Don't call @code{copy-region-as-kill} in Lisp programs unless you aim to 738 Don't call @code{copy-region-as-kill} in Lisp programs unless you aim to
714 support Emacs 18. For Emacs 19, it is better to use @code{kill-new} or 739 support Emacs 18. For Emacs 19, it is better to use @code{kill-new} or
715 @code{kill-append} instead. @xref{Low-Level Kill Ring}. 740 @code{kill-append} instead. @xref{Low-Level Kill Ring}.
716 @end deffn 741 @end deffn
1071 1096
1072 You can use Auto Fill mode (@pxref{Auto Filling}) to fill text 1097 You can use Auto Fill mode (@pxref{Auto Filling}) to fill text
1073 automatically as you insert it, but changes to existing text may leave 1098 automatically as you insert it, but changes to existing text may leave
1074 it improperly filled. Then you must fill the text explicitly. 1099 it improperly filled. Then you must fill the text explicitly.
1075 1100
1076 Most of the functions in this section return values that are not 1101 Most of the commands in this section return values that are not
1077 meaningful. 1102 meaningful. All the functions that do filling take note of the current
1103 left margin, current right margin, and current justification style. If
1104 the current justification style is @code{none}, the filling functions
1105 don't actually do anything.
1078 1106
1079 @deffn Command fill-paragraph justify-flag 1107 @deffn Command fill-paragraph justify-flag
1080 @cindex filling a paragraph 1108 @cindex filling a paragraph
1081 This command fills the paragraph at or after point. If 1109 This command fills the paragraph at or after point. If
1082 @var{justify-flag} is non-@code{nil}, each line is justified as well. 1110 @var{justify-flag} is non-@code{nil}, each line is justified as well.
1121 1149
1122 @deffn Command fill-region-as-paragraph start end &optional justify-flag 1150 @deffn Command fill-region-as-paragraph start end &optional justify-flag
1123 This command considers a region of text as a paragraph and fills it. If 1151 This command considers a region of text as a paragraph and fills it. If
1124 the region was made up of many paragraphs, the blank lines between 1152 the region was made up of many paragraphs, the blank lines between
1125 paragraphs are removed. This function justifies as well as filling when 1153 paragraphs are removed. This function justifies as well as filling when
1126 @var{justify-flag} is non-@code{nil}. In an interactive call, any 1154 @var{justify-flag} is non-@code{nil}. The precise value of
1127 prefix argument requests justification. 1155 @var{justify-flag} specifies a style of justification, as in
1156 @code{justify-current-line}, below.
1157
1158 In an interactive call, any prefix argument requests justification.
1128 1159
1129 In Adaptive Fill mode, which is enabled by default, 1160 In Adaptive Fill mode, which is enabled by default,
1130 @code{fill-region-as-paragraph} on an indented paragraph when there is 1161 @code{fill-region-as-paragraph} on an indented paragraph when there is
1131 no fill prefix uses the indentation of the second line of the paragraph 1162 no fill prefix uses the indentation of the second line of the paragraph
1132 as the fill prefix. 1163 as the fill prefix.
1133 @end deffn 1164 @end deffn
1134 1165
1135 @deffn Command justify-current-line 1166 @deffn Command justify-current-line how eop nosqueeze
1136 This command inserts spaces between the words of the current line so 1167 This command inserts spaces between the words of the current line so
1137 that the line ends exactly at @code{fill-column}. It returns 1168 that the line ends exactly at @code{fill-column}. It returns
1138 @code{nil}. 1169 @code{nil}.
1139 @end deffn 1170
1171 The argument @var{how}, if non-@code{nil} specifies explicitly the style
1172 of justification. It can be @code{left}, @code{right}, @code{full},
1173 @code{center}, or @code{none}. If it is @code{t}, that means to do
1174 follow specified justification style (see @code{current-justification},
1175 below). @code{nil} means to do full justification.
1176
1177 If @var{eop} is non-@code{nil}, that means do left-justification when
1178 @code{current-justification} specifies full justification. This is used
1179 for the last line of a paragraph; even if the paragraph as a whole is
1180 fully justified, the last line should not be.
1181
1182 If @var{nosqueeze} is non-@code{nil}, that means do not change interior
1183 whitespace.
1184 @end deffn
1185
1186 @defopt default-justification
1187 This variable's value specifies the style of justification to use for
1188 text that doesn't specify a style with a text property. The possible
1189 values are @code{left}, @code{right}, @code{full}, @code{center}, or
1190 @code{none}.
1191 @end defopt
1192
1193 @defun current-justification
1194 This function returns the proper justification style to use for filling
1195 the text around point.
1196 @end defun
1140 1197
1141 @defopt fill-prefix 1198 @defopt fill-prefix
1142 This variable specifies a string of text that appears at the beginning 1199 This variable specifies a string of text that appears at the beginning
1143 of normal text lines and should be disregarded when filling them. Any 1200 of normal text lines and should be disregarded when filling them. Any
1144 line that fails to start with the fill prefix is considered the start of 1201 line that fails to start with the fill prefix is considered the start of
1166 @code{(default-value 'fill-column)}. 1223 @code{(default-value 'fill-column)}.
1167 1224
1168 The default value for @code{default-fill-column} is 70. 1225 The default value for @code{default-fill-column} is 70.
1169 @end defvar 1226 @end defvar
1170 1227
1228 @defvar fill-paragraph-function
1229 This variable provides a way for major modes to override the filling of
1230 paragraphs. If the value is non-@code{nil}, @code{fill-paragraph} calls
1231 this function to do the work. If the function returns a non-@code{nil}
1232 value, @code{fill-paragraph} assumes the job is done, and immediately
1233 returns that value.
1234
1235 The usual use of this feature is to fill comments in programming
1236 language modes. If the function needs to fill a paragraph in the usual
1237 way, it can do so as follows:
1238
1239 @example
1240 (let ((fill-paragraph-function nil))
1241 (fill-paragraph arg))
1242 @end example
1243 @end defvar
1244
1245 @deffn Command set-left-margin from to margin
1246 This sets the @code{left-margin} property on the text from @var{from} to
1247 @var{to} to the value @var{margin}. If Auto Fill mode is enabled, this
1248 command also refills the region to fit the new margin.
1249 @end deffn
1250
1251 @deffn Command set-right-margin from to margin
1252 This sets the @code{fill-colmn} property on the text from @var{from} to
1253 @var{to} so as to yield a right margin of width @var{margin}. If Auto
1254 Fill mode is enabled, this command also refills the region to fit the
1255 new margin.
1256 @end deffn
1257
1258 @defun current-left-margin
1259 This function returns the proper left margin value to use for filling
1260 the text around point. The value is the sum of the @code{left-margin}
1261 property of the character at the start of the current line (or zero if
1262 none), plus the value of the variable @code{left-margin}.
1263 @end defun
1264
1265 @defun current-fill-column
1266 This function returns the proper fill column value to use for filling
1267 the text around point. The value is the value of the @code{fill-column}
1268 variable, minus the value of the @code{right-margin} property of the
1269 character after point.
1270 @end defun
1271
1272 @deffn Command move-to-left-margin &optional n force
1273 This function moves point to the left margin of the current line. The
1274 column moved to is determined by calling the function
1275 @code{current-left-margin}. If the argument @var{n} is specified,
1276 @code{move-to-left-margin} moves forward @var{n}@minus{}1 lines first.
1277
1278 If @var{force} is non-@code{nil}, that says to fix the line's
1279 indentation if that doesn't match the left margin value.
1280 @end deffn
1281
1282 @defun delete-to-left-margin from to
1283 This function removes left margin indentation from the text
1284 between @var{from} and @var{to}. The amount of indentation
1285 to delete is determined by calling @code{current-left-margin}.
1286 In no case does this function delete non-whitespace.
1287 @end defun
1288
1171 @node Auto Filling 1289 @node Auto Filling
1172 @comment node-name, next, previous, up 1290 @comment node-name, next, previous, up
1173 @section Auto Filling 1291 @section Auto Filling
1174 @cindex filling, automatic 1292 @cindex filling, automatic
1175 @cindex Auto Fill mode 1293 @cindex Auto Fill mode
1178 as inserted. This section describes the hook used by Auto Fill mode. 1296 as inserted. This section describes the hook used by Auto Fill mode.
1179 For a description of functions that you can call explicitly to fill and 1297 For a description of functions that you can call explicitly to fill and
1180 justify existing text, see @ref{Filling}. 1298 justify existing text, see @ref{Filling}.
1181 1299
1182 @defvar auto-fill-function 1300 @defvar auto-fill-function
1183 The value of this variable should be a function (of no arguments) to 1301 The value of this variable should be a function (of no arguments) to be
1184 be called after self-inserting a space at a column beyond 1302 called after self-inserting a space or a newline. It may be @code{nil},
1185 @code{fill-column}. It may be @code{nil}, in which case nothing 1303 in which case nothing special is done in that case.
1186 special is done.
1187 1304
1188 The value of @code{auto-fill-function} is @code{do-auto-fill} when 1305 The value of @code{auto-fill-function} is @code{do-auto-fill} when
1189 Auto-Fill mode is enabled. That is a function whose sole purpose is to 1306 Auto-Fill mode is enabled. That is a function whose sole purpose is to
1190 implement the usual strategy for breaking a line. 1307 implement the usual strategy for breaking a line.
1191 1308
1933 @menu 2050 @menu
1934 * Examining Properties:: Looking at the properties of one character. 2051 * Examining Properties:: Looking at the properties of one character.
1935 * Changing Properties:: Setting the properties of a range of text. 2052 * Changing Properties:: Setting the properties of a range of text.
1936 * Property Search:: Searching for where a property changes value. 2053 * Property Search:: Searching for where a property changes value.
1937 * Special Properties:: Particular properties with special meanings. 2054 * Special Properties:: Particular properties with special meanings.
2055 * Format Properties:: Properties for representing formatting of text.
1938 * Sticky Properties:: How inserted text gets properties from 2056 * Sticky Properties:: How inserted text gets properties from
1939 neighboring text. 2057 neighboring text.
1940 * Saving Properties:: Saving text properties in files, and reading 2058 * Saving Properties:: Saving text properties in files, and reading
1941 them back. 2059 them back.
1942 * Not Intervals:: Why text properties do not use 2060 * Not Intervals:: Why text properties do not use
1984 This function returns the entire property list of the character at 2102 This function returns the entire property list of the character at
1985 @var{position} in the string or buffer @var{object}. If @var{object} is 2103 @var{position} in the string or buffer @var{object}. If @var{object} is
1986 @code{nil}, it defaults to the current buffer. 2104 @code{nil}, it defaults to the current buffer.
1987 @end defun 2105 @end defun
1988 2106
2107 @defvar default-text-properties
2108 This variable holds a property list giving default values for text
2109 properties. Whenever a character does not specify a value for a
2110 property, the value stored in this list is used instead. Here is an
2111 example:
2112
2113 @example
2114 (setq default-text-properties '(foo 69))
2115 ;; @r{Make sure character 1 has no properties of its own.}
2116 (set-text-properties 1 2 nil)
2117 ;; @r{What we get, when we ask, is the default value.}
2118 (get-text-property 1 'foo)
2119 @result{} 69
2120 @end example
2121 @end defvar
2122
1989 @node Changing Properties 2123 @node Changing Properties
1990 @subsection Changing Text Properties 2124 @subsection Changing Text Properties
1991 2125
1992 The primitives for changing properties apply to a specified range of 2126 The primitives for changing properties apply to a specified range of
1993 text. The function @code{set-text-properties} (see end of section) sets 2127 text. The function @code{set-text-properties} (see end of section) sets
2065 2199
2066 @example 2200 @example
2067 (set-text-properties @var{start} @var{end} nil) 2201 (set-text-properties @var{start} @var{end} nil)
2068 @end example 2202 @end example
2069 @end defun 2203 @end defun
2204
2205 See also the function @code{buffer-substring-without-properties}
2206 (@pxref{Buffer Contents}) which copies text from the buffer
2207 but does not copy its properties.
2070 2208
2071 @node Property Search 2209 @node Property Search
2072 @subsection Property Search Functions 2210 @subsection Property Search Functions
2073 2211
2074 In typical use of text properties, most of the time several or many 2212 In typical use of text properties, most of the time several or many
2186 2324
2187 @item face 2325 @item face
2188 @cindex face codes of text 2326 @cindex face codes of text
2189 @kindex face @r{(text property)} 2327 @kindex face @r{(text property)}
2190 You can use the property @code{face} to control the font and color of 2328 You can use the property @code{face} to control the font and color of
2191 text. @xref{Faces}, for more information. This feature is temporary; 2329 text. Its value is a face name or a list of face names. @xref{Faces},
2192 in the future, we may replace it with other ways of specifying how to 2330 for more information. This feature may be temporary; in the future, we
2193 display text. 2331 may replace it with other ways of specifying how to display text.
2194 2332
2195 @item mouse-face 2333 @item mouse-face
2196 @kindex mouse-face @r{(text property)} 2334 @kindex mouse-face @r{(text property)}
2197 The property @code{mouse-face} is used instead of @code{face} when the 2335 The property @code{mouse-face} is used instead of @code{face} when the
2198 mouse is on or near the character. For this purpose, ``near'' means 2336 mouse is on or near the character. For this purpose, ``near'' means
2223 special trick: bind @code{inhibit-read-only} to a non-@code{nil} value 2361 special trick: bind @code{inhibit-read-only} to a non-@code{nil} value
2224 and then remove the property. @xref{Read Only Buffers}. 2362 and then remove the property. @xref{Read Only Buffers}.
2225 2363
2226 @item invisible 2364 @item invisible
2227 @kindex invisible @r{(text property)} 2365 @kindex invisible @r{(text property)}
2228 A non-@code{nil} @code{invisible} property means a character does not 2366 A non-@code{nil} @code{invisible} property can make a character invisible
2229 appear on the screen. This works much like selective display. Details 2367 on the screen. @xref{Invisible Text}, for details.
2230 of this feature are likely to change in future versions, so check the
2231 @file{etc/NEWS} file in the version you are using.
2232 2368
2233 @item intangible 2369 @item intangible
2234 @kindex intangible @r{(text property)} 2370 @kindex intangible @r{(text property)}
2235 A non-@code{nil} @code{intangible} property on a character prevents 2371 If a group of consecutive characters have equal and non-@code{nil}
2236 putting point before that character. If you try, point actually goes 2372 @code{intangible} properties, then you cannot place point between them.
2237 after the character (and after all succeeding intangible characters). 2373 If you move point forward into the group, point actually moves to the
2374 end of the group. If you try to move point backward into the group,
2375 point actually moves to the start of the group.
2376
2377 When the variable @code{inhibit-point-motion-hooks} is non-@code{nil},
2378 the @code{intangible} property is ignored.
2238 2379
2239 @item modification-hooks 2380 @item modification-hooks
2240 @cindex change hooks for a character 2381 @cindex change hooks for a character
2241 @cindex hooks for changing a character 2382 @cindex hooks for changing a character
2242 @kindex modification-hooks @r{(text property)} 2383 @kindex modification-hooks @r{(text property)}
2296 value of point runs these hook functions. 2437 value of point runs these hook functions.
2297 @end table 2438 @end table
2298 2439
2299 @defvar inhibit-point-motion-hooks 2440 @defvar inhibit-point-motion-hooks
2300 When this variable is non-@code{nil}, @code{point-left} and 2441 When this variable is non-@code{nil}, @code{point-left} and
2301 @code{point-entered} hooks are not run. 2442 @code{point-entered} hooks are not run, and the @code{intangible}
2443 property has no effect.
2302 @end defvar 2444 @end defvar
2445
2446 @node Format Properties
2447 @section Formatted Text Properties
2448
2449 These text properties affect the behavior of the fill commands. They
2450 are used for representing formatted text. @xref{Filling}.
2451
2452 @table code
2453 @item hard
2454 If a newline character has this property, it is a ``hard'' newline.
2455 The fill commands do not alter hard newlines and do not move words
2456 across them. However, this property takes effect only if the variable
2457 @code{use-hard-newlines} is non-@code{nil}.
2458
2459 @item right-margin
2460 This property specifies the right margin for filling this part of the
2461 text.
2462
2463 @item left-margin
2464 This property specifies the left margin for filling this part of the
2465 text.
2466
2467 @item justification
2468 This property specifies the style of justification for filling this part
2469 of the text.
2470 @end table
2303 2471
2304 @node Sticky Properties 2472 @node Sticky Properties
2305 @subsection Stickiness of Text Properties 2473 @subsection Stickiness of Text Properties
2306 @cindex sticky text properties 2474 @cindex sticky text properties
2307 @cindex inheritance of text properties 2475 @cindex inheritance of text properties