src/ Functions.js

This file contains the lion’s share of APIs and functions used to manipulate the 9ne editor.  In general, function names with underscores (my_function) are APIs and can be used in extension functions.  If a function has Override: true a mode can override that function when the mode is activated.  For example,

var nlptr = window.editor_new_line;
window.editor_new_line = function(){
alert("ha ha I stole your new line");
nlptr();
}

Overrides the editor_new_line function (often tied to “enter”), and extends it to show an alert box.

Copyright

2006 Rohan (robr.nosp@m.ohan@gmai.nosp@m.l.com)

Summary
This file contains the lion’s share of APIs and functions used to manipulate the 9ne editor.
Adds a character to the current cursor position by code
Adds a string of text to the current cursor position
returns true if mark1 is before mark2 in the text
Loops over the divs in the editor_text_area and rebuilds the IDs of the divs (line IDs).
Append some text for display in the mini buffer
Used in key chords, append the binding to the minibuffer so 9ne knows it’s part of a chord
display some text in the mini buffer for one second.
Runs a command using the minibuffer.
The basic mode.
main command to add a new line to the editor.
clears the minibuffer text and command buffer
evaluates the current line as javascript instruction
evaluates the current region as javascript instructions
evaluates the current buffer as javascript instructions
command to insert a tab at the current position
deletes the character infront of the cursor.
jumps to the first line / column of the buffer (current file)
jumps to the last line / column of the buffer (current file)
Moves the caret back one character (does not delete).
jumps to the end of the current line
jumps to the beginning of the current line (column 0)
Moves the caret down one line (not add a new line).
scroll up by one line
Move the caret to up one line used for file navigation
scroll down by one line
Moves the caret forward one character.
Deletes the character behind the cursor (backspace).
scrolls the view to the active line so the line is within view.
repositions the view so the active line is in the middle of the viewable screen
Yank the contents of the clipboard.
Save the contents of the buffer
Gets the full contents of the buffer in plain text
removes the active line
delete from the current position to the start of the line
kills (closes) the editor.
sets a mark as an anchor.
deletes from the mark to the point where the kill region function is called, and puts the restuls on the clipboard

Functions

addCharCodeToPosition

function addCharCodeToPosition(code)

Adds a character to the current cursor position by code

Parameters

codethe ascii char code to add

addStringToCurrentPosition

function addStringToCurrentPosition(str)

Adds a string of text to the current cursor position

Parameters

strthe string of text to add

isBefore

function isBefore(mark1,
mark2)

returns true if mark1 is before mark2 in the text

Parameters

mark1the start mark
mark2the end mark

Returns

boolean; true if mark1 is before mark2 in the text

SeeAlso

Mark

recalculateLines

function recalculateLines()

Loops over the divs in the editor_text_area and rebuilds the IDs of the divs (line IDs).

append_minibuffer_text

function append_minibuffer_text(text)

Append some text for display in the mini buffer

Parameters

textThe text to append to the display

append_minibuffer_binding

function append_minibuffer_binding(text)

Used in key chords, append the binding to the minibuffer so 9ne knows it’s part of a chord

Parameters

textchord binding “CTRL+X”, “ALT+Y”, etc

minibuffer_message

function minibuffer_message(text)

display some text in the mini buffer for one second. non-blocking message.  Useful for “mode not found” kind of errors.

Parameters

textthe text to display

run_minibuffer_command

function run_minibuffer_command(cmd)

Runs a command using the minibuffer.  If the function passed in has a “cue” property, a dialog box is shown to collect parameters for the command.  Note the parameter for this function is a string.

Parameters

cmdthe function name to run (optionally taking one parameter and having a cue property)

fundamental_mode

function fundamental_mode()

The basic mode.  This mode has all the default text movement (and most everything else) functions associated with it.  If a mode overrides any functions, setting the buffer to this mode will reset everything to the default.

editor_new_line

window.editor_new_line = function()

main command to add a new line to the editor.  Adds one if at the end of the file or inserts one if in the middle

Override: true

clear_minibuffer

window.clear_minibuffer = function()

clears the minibuffer text and command buffer

Override: true

eval_line

window.eval_line = function()

evaluates the current line as javascript instruction

Override: true

eval_region

window.eval_region = function()

evaluates the current region as javascript instructions

Override: true

eval_buffer

window.eval_buffer = function()

evaluates the current buffer as javascript instructions

Override: true

insert_tab

window.insert_tab = function()

command to insert a tab at the current position

Override: true

delete_char

window.delete_char = function()

deletes the character infront of the cursor. if at the end of the line will move the previous line to the current line

Override: true

beginning_of_buffer

window.beginning_of_buffer = function()

jumps to the first line / column of the buffer (current file)

Override: true

end_of_buffer

window.end_of_buffer = function()

jumps to the last line / column of the buffer (current file)

Override: true

backward_char

window.backward_char = function()

Moves the caret back one character (does not delete). used for file navigation

Override: true

end_of_line

window.end_of_line = function()

jumps to the end of the current line

Override: true

beginning_of_line

window.beginning_of_line = function()

jumps to the beginning of the current line (column 0)

Override: true

next_line

window.next_line = function()

Moves the caret down one line (not add a new line). used for file navigation.

Override: true

scroll_up

window.scroll_up = function()

scroll up by one line

Override: true

previous_line

window.previous_line = function()

Move the caret to up one line used for file navigation

Override: true

scroll_down

window.scroll_down = function()

scroll down by one line

Override: true

forward_char

window.forward_char = function()

Moves the caret forward one character. used for file navigation

Override: true

delete_backward_char

window.delete_backward_char = function()

Deletes the character behind the cursor (backspace). if the cursor is at the beginning of the line it moves up to the previous line

Override: true

scroll_to_line

window.scroll_to_line = function()

scrolls the view to the active line so the line is within view. for example, if you jump to an offscreen line this will move the view region to show that line

Override: true

scroll_to_center

window.scroll_to_center = function()

repositions the view so the active line is in the middle of the viewable screen

Override: true

yank

window.yank = function()

Yank the contents of the clipboard.  In other words, paste

Override: true

save

window.save = function()

Save the contents of the buffer

Override: true

get_editor_text

window.get_editor_text = function()

Gets the full contents of the buffer in plain text

Override: true

kill_line

window.kill_line = function()

removes the active line

Returns

the line text

Override: true

kill_start_line

window.kill_start_line = function()

delete from the current position to the start of the line

Returns

the removed text

Override: true

kill_9ne

window.kill_9ne = function()

kills (closes) the editor. checks to see if the buffer has been modified and verifies if it has been

Returns

Override: true

editor_set_mark

window.editor_set_mark = function()

sets a mark as an anchor. commands that operate on regions will work only after a mark (a start position) has been set

Override: true

copy_region

window.copy_region = function()
from a markcopies the region to the clipboard

Override: true

kill_region

window.kill_region = function()

deletes from the mark to the point where the kill region function is called, and puts the restuls on the clipboard

Override: true;

function addCharCodeToPosition(code)
Adds a character to the current cursor position by code
function addStringToCurrentPosition(str)
Adds a string of text to the current cursor position
function isBefore(mark1,
mark2)
returns true if mark1 is before mark2 in the text
function recalculateLines()
Loops over the divs in the editor_text_area and rebuilds the IDs of the divs (line IDs).
function append_minibuffer_text(text)
Append some text for display in the mini buffer
function append_minibuffer_binding(text)
Used in key chords, append the binding to the minibuffer so 9ne knows it’s part of a chord
function minibuffer_message(text)
display some text in the mini buffer for one second.
function run_minibuffer_command(cmd)
Runs a command using the minibuffer.
function fundamental_mode()
The basic mode.
window.editor_new_line = function()
main command to add a new line to the editor.
window.clear_minibuffer = function()
clears the minibuffer text and command buffer
window.eval_line = function()
evaluates the current line as javascript instruction
window.eval_region = function()
evaluates the current region as javascript instructions
window.eval_buffer = function()
evaluates the current buffer as javascript instructions
window.insert_tab = function()
command to insert a tab at the current position
window.delete_char = function()
deletes the character infront of the cursor.
window.beginning_of_buffer = function()
jumps to the first line / column of the buffer (current file)
window.end_of_buffer = function()
jumps to the last line / column of the buffer (current file)
window.backward_char = function()
Moves the caret back one character (does not delete).
window.end_of_line = function()
jumps to the end of the current line
window.beginning_of_line = function()
jumps to the beginning of the current line (column 0)
window.next_line = function()
Moves the caret down one line (not add a new line).
window.scroll_up = function()
scroll up by one line
window.previous_line = function()
Move the caret to up one line used for file navigation
window.scroll_down = function()
scroll down by one line
window.forward_char = function()
Moves the caret forward one character.
window.delete_backward_char = function()
Deletes the character behind the cursor (backspace).
window.scroll_to_line = function()
scrolls the view to the active line so the line is within view.
window.scroll_to_center = function()
repositions the view so the active line is in the middle of the viewable screen
window.yank = function()
Yank the contents of the clipboard.
window.save = function()
Save the contents of the buffer
window.get_editor_text = function()
Gets the full contents of the buffer in plain text
window.kill_line = function()
removes the active line
window.kill_start_line = function()
delete from the current position to the start of the line
window.kill_9ne = function()
kills (closes) the editor.
window.editor_set_mark = function()
sets a mark as an anchor.
window.copy_region = function()
window.kill_region = function()
deletes from the mark to the point where the kill region function is called, and puts the restuls on the clipboard
A position in the buffer.