Add a newline to a buffer when saving
Int_Type ADD_NEWLINE
If the value of ADD_NEWLINE
is non-zero and the buffer if the
buffer does not end with a newline character, a newline character
will be silently added to the end of a buffer when the buffer is
written out to a file.
Controls the Autosave Interval
Int_Type MAX_HITS
The value of the MAX_HITS
variable specifies how many ``hits''
a buffer can take before it is autosaved. A hit is defined as a
single key sequence that could modify the buffer.
The TAB setting for the current buffer
Int_Type TAB
The TAB
variable specifies the tab setting for the current
buffer.
TAB_DEFAULT, USE_TABS
autosave
Void autosave ();
The autosave
function saves the current buffer in an auto save file
if the buffer has been marked for the auto save operation.
setbuf_info, autosaveall
MAX_HITS
autosaveall
Void autosaveall ();
This function is like autosave
except that it causes all files
marked for the auto save operation to be auto-saved.
autosave, setbuf_info
MAX_HITS
buffer_list
Integer buffer_list ();
This function returns an integer indicating the number of buffers and leaves the names of the buffers on the stack. For example, the following function displays the names of all buffers attached to files:
define show_buffers ()
{
variable b, str = "", file;
loop (buffer_list ())
{
b = ();
setbuf (b);
(file,,,) = getbuf_info ();
if (strlen (file)) str = strcat (str, strcat (" ", b));
}
message (str);
}
getbuf_info, whatbuf
buffer_visible
Integer buffer_visible (String buf);
This function is used to determine whether or not a buffer with name
specified by the string buf
is in a window or not. More explicitly,
it returns the number of windows containing buf
. This means that if
buf
does not occupy a window, it returns zero. For Example,
define find_buffer_in_window (buf)
{
!if (buffer_visible (buf)) return 0;
pop2buf (buf);
return 1;
}
is a function that moves to the window containing buf
if buf
is in
a window.
bufferp, nwindows
bufferp
Integer bufferp (String buf);
This function is used to see if a buffer exists or not. If a buffer with
name buf
exists, it returns a non-zero value. If it does not exist,
it returns zero.
setbuf, getbuf_info
bury_buffer
Void bury_buffer (String name);
The bury_buffer
function may be used to make it unlikely for the
buffer specified by the paramter name
to appear in a window.
sw2buf, getbuf_info
Check to see if any buffers have been changed on the disk
check_buffers ();
The check_buffers
function checks to see whether or not any of
the disk files that are associated with the editor's buffers have been
modified since the assocation was made. The buffer flags are
updated accordingly.
file_time_compare, file_changed_on_disk
delbuf
Void delbuf (String buf);
delbuf
may be used to delete a buffer with the name specified by
buf
. If the buffer does not exist, a S-Lang error will be generated.
whatbuf, bufferp, sw2buf
getbuf_info
getbuf_info ();
This function returns values to the stack. The four values from the top are:
Integer % buffer flags
String % name of buffer
String % directory associated with buffer
String % name of file associated with buffer (if any).
The integer that corresponds to the buffer flags are encoded as:
bit 0: buffer modified
bit 1: auto save mode
bit 2: file on disk modified
bit 3: read only bit
bit 4: overwrite mode
bit 5: undo enabled
bit 6: buffer buried
bit 7: Force save upon exit.
bit 8: Do not backup
bit 9: File associated with buffer is a binary file
bit 10: Add CR to end of lines when writing buffer to disk.
bit 11: Abbrev mode
For example,
(file,,,flags) = getbuf_info();
returns the file and the flags associated with the current buffer.
setbuf_info, whatbuf
pop2buf
Void pop2buf (String buf);
The pop2buf
function will switch to another window and display the
buffer specified by buf
in it. If buf
does not exist, it will be
created. If buf
already exists in a window, the window containing
buf
will become the active one. This function will create a new
window if necessary. All that is guaranteed is that the current
window will continue to display the same buffer before and after the
call to pop2buf
.
whatbuf, pop2buf_whatbuf, setbuf, sw2buf, nwindows
pop2buf_whatbuf
String pop2buf_whatbuf (String buf);
This function performs the same function as pop2buf
except that the
name of the buffer that buf
replaced in the window is returned.
This allows one to restore the buffer in window to what it was before
the call to pop2buf_whatbuf
.
pop2buf, whatbuf
set_buffer_hook
Void set_buffer_hook (String hook, String f);
Set current buffer hook hook
to function f
. f
is a user
defined S-Lang function. Currently, hook
can be any one of:
"par_sep" -- returns zero if the current line does not
constitute the beginning or end of a paragraph.
It returns non-zero otherwise. The default value of hook is
is_paragraph_separator.
"indent_hook" -- returns nothing. It is called by the indent line
routines.
"wrap_hook" hook that is called after a line is wrapped. Returns
nothing.
"newline_indent_hook" --- returns nothing. If this hook is defined,
it will be called instead of the internal function
newline_and_indent is called.
"bob_eob_error_hook" --- returns nothing. If this hook is defined,
it will be called whenever an error one of the internal cursor
movement functions would have generated an end of buffer or beginning of
buffer error. It is passed an integer that indicates which function
would have generated the error. Specifically:
-1 previous_line_cmd
-2 previous_char_cmd
-3 page_up
1 next_line_cmd
2 next_char_cmd
3 page_down
"mouse_down", "mouse_up", "mouse_drag" "mouse_2click" "mouse_3click"
These hooks are used to override default hooks defined by the
mouse_set_default_hook function.
unset_buffer_hook, mouse_set_default_hook
set_buffer_umask
Integer set_buffer_umask (Integer cmask);
The function may be used to set the process file creation mask
for the appropriate operations associated with the current
buffer. This makes it possible to have a buffer-dependent
umask setting. The function takes the desired umask setting and
returns the previous setting. If cmask
is zero, the default
process umask setting will be used for operations while the buffer
is current. If cmask
is -1, the umask associated with the buffer
will not be changed.
set_mode
Void set_mode(String mode, Integer flags);
This function sets buffer mode flags and status line mode name. mode
is a string which is displayed on the status line if the %m
status
line format specifier is used. The second argument, flags
is an
integer with the possible values:
0 : no mode. Very generic
1 : Wrap mode. Lines are automatically wrapped at wrap column.
2 : C mode.
4 : Language mode. Mode does not wrap but is useful for computer
languages.
8 : S-Lang mode
16: Fortran mode highlighting
32: TeX mode highlighting
whatmode, getbuf_info, setbuf_info.
setbuf
Void setbuf(String buf);
Changes the default buffer to one named buf
. If the buffer does not
exist, it will be created.
Note: This change only lasts until top
level of editor loop is reached at which point the the buffer
associated with current window will be made the default. That is this
change should only be considered as temporary. To make a long lasting
change, use the function sw2buf
.
sw2buf, pop2buf, whatbuf, pop2buf_whatbuf
setbuf_info
Void setbuf_info(String file, String dir, String buf, Integer flags);
This function may be used to change attributes regarding the current
buffer. It performs the opposite function of the related function
getbuf_info
. Here file
is the name of the file to be associated
with the buffer; dir
is the directory to be associated with the
buffer; buf
is the name to be assigned to the buffer, and flags
describe the buffer attributes. See getbuf_info
for a discussion of
flags
. Note that the actual file associated with the buffer is
located in directory dir
with the name file
.
For example, the function
define set_overwrite_mode ()
{
variable dir, file, flags, name;
(file, dir, name, flags) = getbuf_info ();
flags = flags | (1 shl 4);
setbuf_info (file, dir, name, flags);
}
may be used to turn on overwrite mode for the current buffer. Note
that it is better exploit the fact that S-Lang is a stack based language
and simply write the above function as:
define set_overwrite_mode ()
{
setbuf_info (getbuf_info () | 0x10);
}
Here, (1 shl 4)
has been written as the hexidecimal number 0x10
.
getbuf_info, setbuf, whatbuf
sw2buf
Void sw2buf (String buf);
This function is used to switch to another buffer whose name is
specified by the parameter buf
. If the buffer specified by buf
does not exist, one will be created.
Note: Unlike setbuf
, the change
to the new buffer is more permanent in the sense that when control
passed back out of S-Lang to the main editor loop, if the current
buffer at that time is the buffer specified here, this buffer will be
attached to the window.
setbuf, pop2buf, bufferp
what_mode
(String name, Integer flags) = Integer what_mode ();
This function may be used to obtain the mode flags and mode name of the
current buffer. See set_mode
for more details.
set_mode, getbuf_info, setbuf_info
whatbuf
String what_buffer();
whatbuf
returns the name of the current buffer. It is usually used
in functions when one wants to work with more than one buffer. The
function setbuf_info
may be used to change the name of the buffer.
getbuf_info, bufferp
write_buffer
Integer write_buffer (String filename);
This function may be used to write the current buffer out to a file
specified by filename
. The buffer will then become associated with
that file. The number of lines written to the file is returned. An
error condition will be signaled upon error.
write_region_to_file, setbuf_info