# Minimum Profit Function Reference

Lee Page <lrpage AT mindspring POINT com>

Clipboard (mp_clipboard.mpsl) Core (mp_core.mpsl) Crypt (mp_crypt.mpsl) Editor Actions (mp_drv.mpsl) Editor (mp_edit.mpsl) File (mp_file.mpsl) Keys (mp_keyseq.mpsl) Macros (mp_macro.mpsl) Misc. (mp_misc.mpsl) | Movement (mp_move.mpsl) Search (mp_search.mpsl) Sessions (mp_session.mpsl) Spell (mp_ispell.mpsl) Syntax Highlighting (mp_syntax.mpsl) Tags (mp_tags.mpsl) Templates (mp_templates.mpsl) TUI (mp_tui.mpsl)

## Clipboard (mp_clipboard.mpsl)

    mp.unmark(doc)
| Unmarks the block.
    mp.mark(doc)
| Marks the start or end of the block.
    mp.get_active_area(doc)
| Returns the active area: the selection, or the full document.
    mp.copy(doc)
| Copies the mark to the clipboard.
    mp.delete_mark(doc)
| Deletes current selection.
    mp.cut(doc)
| Cut (copy + delete) selected mark.
    mp.paste(doc)
| Pastes from the clipboard to the cursor position.

## Core (mp_core.mpsl)

    mp.active()
| Returns the active document.
    mp.process_action(a)
| Processes an action.
    mp.process_event(k)
| Processes a key event.
    mp.build_status_line()
| Returns the string to be drawn in the status line.
    mp.backslash_codes(s, d)
| Encodes (d == 0) or decodes (d == 1) backslash codes.
    mp.long_op(func, a1, a2, a3)
| Executes a potentially long function (sets as busy).
    mp.get_history(key)
| Returns a history for the specified key.
    mp.menu_label(action)
| Returns a label for the menu for an action.
    mp.usage()
| Set mp.exit_message with a usage message (--help).
    mp.process_cmdline()
| Process the command line arguments (ARGV).
    mp.load_profile()
| Loads ~/.mp.mpsl.
    mp.normalize_version(vs)
| Converts a version string to something usable with cmp().
    mp.assert_version(found, minimal, package)
| Asserts that 'found' version of 'package' is at least 'minimal', or generate a warning otherwise.
    mp.test_versions()
| Tests component versions.

## Crypt (mp_crypt.mpsl)

    mp.arcfour_byte()
| Gets next ARCFOUR byte next char is chr(ord(getchar(l)) ^ mp.arcfour_byte()).
    mp.arcfour_init(key)
| Initializes an ARCFOUR cypher.
    mp.crypt1_load(fd, password)
| Loads a crypt1 encrypted file into lines.
    mp.crypt1_save(fd, lines, password)
| Saves the lines as a crypt1 encrypted file.
    mp.crypt1_detect(fd)
| Detects if fd is an mpcrypt1-type file.

## Editor Actions (mp_drv.mpsl)

    mp.drv.menu()
    mp.drv.clip_to_sys()
    mp.drv.sys_to_clip()
    mp.drv.update_ui()
    mp.drv.timer(msecs,func)
    mp.drv.busy(onoff)
    mp.update_ui()
    mp.alert(msg)
    mp.confirm(msg)
    mp.openfile(prompt)
    mp.savefile(prompt)
    mp.form(widgets)
    mp.timer(msecs,func)
    mp.busy(onoff)

## Editor (mp_edit.mpsl)

    mp.break_line(doc, col)
| Breaks current line in two (inserts a newline).
    mp.join_line(doc)
| Joins the current line with the next one.
    mp.delete_line(doc)
| Deletes the current line.
    mp.delete_char(doc)
| Deletes the current char.
    mp.delete_range(doc, bx, by, ex, ey)
| Deletes a range of characters from a document.
    mp.insert_string(doc, str)
| Inserts a string into the cursor position. Note: newlines are not allowed. You must call mp.insert_newline() to manually insert a newline.
    mp.insert(doc, a)
| Inserts an array of text into a document.
    mp.wrap_words(doc)
| Do word wrapping.
    mp.insert_space(doc)
| Inserts a space, taking word wrapping into account.
    mp.insert_tab(doc)
| Inserts a tab.
    mp.insert_newline(doc)
| Inserts a newline.
    mp.insert_keystroke(doc, key)
| Inserts from a keystroke (with undo).
    mp.store_undo(doc)
| Stores the current txt in the undo queue.
    mp.undo(doc)
| Undoes the last operation.
    mp.redo(doc)
| Redoes the last operation undone.
    mp.join_paragraph(doc)
| Joins the current paragraph into just one line.
    mp.word_wrap_paragraph(doc)
| Word wraps current paragraph.

## File (mp_file.mpsl)

    mp.chomp(str)
| Chomps the end of file (should this be: end of line?) chars from a string.
    mp.open_file_for_reading(filename)
| The three-state file opening of text editors: open if possible, fail on errors, create new if non-existent. Note: this is a low-level interface. You probably want to use mp.open( filename ).
    mp.save(doc)
| Saves a file.
    mp.new(filename, lines)
| Creates a new document.
    mp.next()
| Rotates through the document list.
    mp.prev()
| Rotates through the document list, backwards.
    mp.close()
| Closes the active document.
    mp.find_file_by_name(filename)
| Finds an open file by its name, returns the index to the file in the document array.
    mp.open(filename)
| Opens a new document (uses UI). This interface checks to make sure the file isn't already open, as well as checking to see if the file is encrypted. Will prompt for a password if it is encrypted.

## Keys (mp_keyseq.mpsl)

    mp.pending_key()
    mp.process_keyseq(key)
    mp.add_keyseq(seq, keycode)

## Macros (mp_macro.mpsl)

    mp.process_event_and_record(k)
| Patched version of mp.process_event().
    mp.record_macro
| Start recording a macro.
    mp.play_macro
| Play a macro.

## Misc. (mp_misc.mpsl)

    mp.dump(v)
| Overrides the MPSL dump() function, dumping into the active text document.

## Movement (mp_move.mpsl)

    mp.move(doc, func)
| Wrapper for movement functions, with possible shift selection.
    mp.split_by_words(s)
| Splits a string by words.
    mp.split_line_by_words(doc, r)
| Splits current line by words and returns a three element array containing the list of words, the list of offsets and the current position.
    mp.get_word(doc, r)
| Returns the word under the cursor.
    mp.get_range(doc, bx, by, ex, ey)
| Gets a range or characters from a document.
    mp.set_x(doc, x)
| Sets the x position.
    mp.set_y(doc, y)
| Sets the y position.
    mp.move_up(doc)
| Moves one line up.
    mp.move_down(doc)
| Moves one line down.
    mp.move_pgup(doc)
| Moves one page up.
    mp.move_pgdn(doc)
| Moves one page down.
    mp.move_left(doc)
| Moves one char left.
    mp.move_right(doc)
| Moves one char right.
    mp.move_bol(doc)
| Moves to the beginning of the line.
    mp.move_eol(doc)
| Moves to the end of the line.
    mp.move_bof(doc)
| Moves to the beginning of the file.
    mp.move_eof(doc)
| Moves to the end of the file.
    mp.move_word_left(doc)
| Moves a word to the left.
    mp.move_word_right(doc)
| Moves a word to the right.
    mp.move_to_coords_xy(doc, x, y)
| Move the cursor to the character on the visual coords x and y. See also: mp.set_x( doc, x ), mp.set_y( doc, y ).

## Search (mp_search.mpsl)

    mp.prefix_regex(str)
| Set str to be a valid regex.
    mp.search_dir(doc, str, dir)
| Search str and put the current position there, with direction.
    mp.search(doc, str)
| Search str and put the current position there, downwards.
    mp.search_back(doc, str)
| Search str and put the current position there, backwards.
    mp.replace_1(doc, this, that)
| Searches 'this' and replaces it with 'that', once.
    mp.replace(doc, this, that)
| Replaces 'this' with 'that', may be globally.
    mp.seek_prev_or_next_char(doc, func)
| Moves to next or previous occurrence of current char.
    mp.grep(rx, spec)
| Greps str in the files in spec. Returns NULL if no file matched the glob() (or glob() is unsupported), an empty list if the string was not found or an array with the matches, that are three-element arrays with the file name, the line number and the line that matched.

## Sessions (mp_session.mpsl)

    mp.session_file()
| Returns the appropriate session saving file.
    mp.save_session()
| Saves currently open files as a session. Returns: -1, nothing to save; -2, error saving; or 0, session correctly saved.
    mp.load_session()
| Loads a session. Returns: -1, no session, -2, user cancellation on closing currently open documents and 0, ok.

## Spell (mp_ispell.mpsl)

    mp.open_ispell_pipe
| Opens the pipe to ispell.
    mp.close_ispell_pipe
| Closes the pipe to ispell.
    mp.ispell_word_color_func(w)
| mp.word_color_func() for ispell.
    mp.ispell(b)
| Sets or unsets spell checking (-1, toggle).

## Syntax Highlighting (mp_syntax.mpsl)

    mp.syn_token_list(l)
| Initializes the language syntax highlighting lists.
    mp.detect_syntax(doc)
| Tries to detect the syntax of a document.
    mp.help(doc, word)

## Tags (mp_tags.mpsl)

    mp.load_tags(force)
| Load a 'tags' file.
    mp.open_tag(tag)
| Opens a tag (interactive).
    mp.complete(d, list, label)
| Completes the current word given a list (interactive).

## Templates (mp_templates.mpsl)

    mp.read_templates_file()
| Reads the $HOME/.mp_templates file into mp.templates.

## TUI (mp_tui.mpsl)

    mp.tui.prompt(prompt)
| Draw a prompt on screen.
    mp.tui.readline(prompt, history, default, flags)
| The readline function, with special functionality in 'flags'. Returns the string typed in.
    mp.tui.list(prompt, data, pos)
| Select from a list. Returns the index into data that was selected.
    mp.drv.alert(msg)
    mp.drv.confirm(msg, def)
    mp.drv.openfile(prompt)
    mp.drv.savefile(prompt)
    mp.drv.form(widgets)
    mp.drv.menu()
    mp.drv.busy(onoff)