Next Previous Contents

4. Buffer Related Functions

4.1 ADD_NEWLINE

Synopsis

Add a newline to a buffer when saving

Usage

Int_Type ADD_NEWLINE

Description

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.

4.2 MAX_HITS

Synopsis

Controls the Autosave Interval

Usage

Int_Type MAX_HITS

Description

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.

See Also

4.3 TAB

Synopsis

The TAB setting for the current buffer

Usage

Int_Type TAB

Description

The TAB variable specifies the tab setting for the current buffer.

See Also

TAB_DEFAULT, USE_TABS

4.4 autosave

Synopsis

autosave

Usage

Void autosave ();

Description

The autosave function saves the current buffer in an auto save file if the buffer has been marked for the auto save operation.

See Also

setbuf_info, autosaveall

See Also

MAX_HITS

4.5 autosaveall

Synopsis

autosaveall

Usage

Void autosaveall ();

Description

This function is like autosave except that it causes all files marked for the auto save operation to be auto-saved.

See Also

autosave, setbuf_info

See Also

MAX_HITS

4.6 buffer_list

Synopsis

buffer_list

Usage

Integer buffer_list ();

Description

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);
        }
See Also

getbuf_info, whatbuf

4.7 buffer_visible

Synopsis

buffer_visible

Usage

Integer buffer_visible (String buf);

Description

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.
See Also

bufferp, nwindows

4.8 bufferp

Synopsis

bufferp

Usage

Integer bufferp (String buf);

Description

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.

See Also

setbuf, getbuf_info

4.9 bury_buffer

Synopsis

bury_buffer

Usage

Void bury_buffer (String name);

Description

The bury_buffer function may be used to make it unlikely for the buffer specified by the paramter name to appear in a window.

See Also

sw2buf, getbuf_info

4.10 check_buffers

Synopsis

Check to see if any buffers have been changed on the disk

Usage

check_buffers ();

Description

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.

See Also

file_time_compare, file_changed_on_disk

4.11 delbuf

Synopsis

delbuf

Usage

Void delbuf (String buf);

Description

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.

See Also

whatbuf, bufferp, sw2buf

4.12 getbuf_info

Synopsis

getbuf_info

Usage

getbuf_info ();

Description

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.
See Also

setbuf_info, whatbuf

4.13 pop2buf

Synopsis

pop2buf

Usage

Void pop2buf (String buf);

Description

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.

See Also

whatbuf, pop2buf_whatbuf, setbuf, sw2buf, nwindows

4.14 pop2buf_whatbuf

Synopsis

pop2buf_whatbuf

Usage

String pop2buf_whatbuf (String buf);

Description

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.

See Also

pop2buf, whatbuf

4.15 set_buffer_hook

Synopsis

set_buffer_hook

Usage

Void set_buffer_hook (String hook, String f);

Description

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.
See Also

unset_buffer_hook, mouse_set_default_hook

4.16 set_buffer_umask

Synopsis

set_buffer_umask

Usage

Integer set_buffer_umask (Integer cmask);

Description

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.

4.17 set_mode

Synopsis

set_mode

Usage

Void set_mode(String mode, Integer flags);

Description

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
See Also

whatmode, getbuf_info, setbuf_info.

4.18 setbuf

Synopsis

setbuf

Usage

Void setbuf(String buf);

Description

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.

See Also

sw2buf, pop2buf, whatbuf, pop2buf_whatbuf

4.19 setbuf_info

Synopsis

setbuf_info

Usage

Void setbuf_info(String file, String dir, String buf, Integer flags);

Description

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.
See Also

getbuf_info, setbuf, whatbuf

4.20 sw2buf

Synopsis

sw2buf

Usage

Void sw2buf (String buf);

Description

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.

See Also

setbuf, pop2buf, bufferp

4.21 what_mode

Synopsis

what_mode

Usage

(String name, Integer flags) = Integer what_mode ();

Description

This function may be used to obtain the mode flags and mode name of the current buffer. See set_mode for more details.

See Also

set_mode, getbuf_info, setbuf_info

4.22 whatbuf

Synopsis

whatbuf

Usage

String what_buffer();

Description

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.

See Also

getbuf_info, bufferp

4.23 write_buffer

Synopsis

write_buffer

Usage

Integer write_buffer (String filename);

Description

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.

See Also

write_region_to_file, setbuf_info


Next Previous Contents