|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.gjt.sp.jedit.Buffer
A Buffer
represents the contents of an open text
file as it is maintained in the computer's memory (as opposed to
how it may be stored on a disk).
In a BeanShell script, you can obtain the current buffer instance from the
buffer
variable.
This class does not have a public constructor.
Buffers can be opened and closed using methods in the jEdit
class.
This class is partially thread-safe, however you must pay attention to two very important guidelines:
Nested Class Summary | |
static class |
Buffer.TokenList
Deprecated. Use org.gjt.sp.jedit.syntax.DefaultTokenHandler instead |
Field Summary | |
static java.lang.String |
BACKED_UP
Backed up property. |
static java.lang.String |
CARET
Caret info properties. |
static java.lang.String |
ENCODING
Character encoding used when loading and saving. |
static java.lang.String |
ENCODING_AUTODETECT
Should jEdit try to set the encoding based on a UTF8, UTF16 or XML signature at the beginning of the file? |
static int |
FILE_CHANGED
|
static int |
FILE_DELETED
|
static int |
FILE_NOT_CHANGED
|
static java.lang.String |
GZIPPED
This property is set to 'true' if the file should be GZipped. |
static int |
HIGH_PRIORITY
|
static java.lang.String |
LINESEP
Line separator property. |
static int |
NORMAL_PRIORITY
|
static java.lang.String |
SCROLL_HORIZ
|
static java.lang.String |
SCROLL_VERT
This should be a physical line number, so that the scroll position is preserved correctly across reloads (which will affect virtual line numbers, due to fold being reset) |
static java.lang.String |
SELECTION
|
static java.lang.String |
TRAILING_EOL
This property is set to 'true' if the file has a trailing newline. |
Method Summary | |
LineManager |
_getLineManager()
Plugins and macros should not call this method. |
void |
addBufferChangeListener(BufferChangeListener listener)
Adds a buffer change listener. |
void |
addBufferChangeListener(BufferChangeListener listener,
int priority)
Adds a buffer change listener. |
void |
addMarker(char shortcut,
int pos)
Adds a marker to this buffer. |
void |
addOrRemoveMarker(char shortcut,
int pos)
If a marker is set on the line of the position, it is removed. |
void |
autosave()
Autosaves this buffer. |
void |
beginCompoundEdit()
Starts a compound edit. |
int |
checkFileStatus(View view)
Check if the buffer has changed on disk. |
javax.swing.text.Position |
createPosition(int offset)
Creates a floating position. |
void |
endCompoundEdit()
Ends a compound edit. |
java.io.File |
getAutosaveFile()
Returns the autosave file for this buffer. |
boolean |
getBooleanProperty(java.lang.String name)
Returns the value of a boolean property. |
BufferChangeListener[] |
getBufferChangeListeners()
Returns an array of registered buffer change listeners. |
java.lang.String |
getContextSensitiveProperty(int offset,
java.lang.String name)
Some settings, like comment start and end strings, can vary between different parts of a buffer (HTML text and inline JavaScript, for example). |
int |
getCurrentIdentForLine(int lineIndex,
int[] whitespaceChars)
Deprecated. Use the correctly spelled getCurrentIndentForLine() instead. |
int |
getCurrentIndentForLine(int lineIndex,
int[] whitespaceChars)
Returns the line's current leading indent. |
javax.swing.text.Element |
getDefaultRootElement()
Deprecated. Use getLineOfOffset() ,
getLineStartOffset() , and
getLineEndOffset() instead. |
java.lang.String |
getDirectory()
Returns the directory containing this buffer. |
java.io.File |
getFile()
Deprecated. Do not call this method, use getPath()
instead. |
int[] |
getFoldAtLine(int line)
Returns an array. |
FoldHandler |
getFoldHandler()
Returns the current buffer's fold handler. |
int |
getFoldLevel(int line)
Returns the fold level of the specified line. |
javax.swing.Icon |
getIcon()
Returns this buffer's icon. |
int |
getIdealIndentForLine(int lineIndex)
Returns the ideal leading indent for the specified line. |
int |
getIndentSize()
Returns the indent size used in this buffer. |
int |
getIndex()
Returns the position of this buffer in the buffer list. |
int |
getIntegerProperty(java.lang.String name,
int defaultValue)
Returns the value of an integer property. |
KeywordMap |
getKeywordMapAtOffset(int offset)
Returns the syntax highlighting keyword map in effect at the specified offset. |
long |
getLastModified()
Returns the last time jEdit modified the file on disk. |
int |
getLength()
Returns the number of characters in the buffer. |
int |
getLineCount()
Returns the number of physical lines in the buffer. |
int |
getLineEndOffset(int line)
Returns the end offset of the specified line. |
int |
getLineLength(int line)
Returns the length of the specified line. |
int |
getLineOfOffset(int offset)
Returns the line containing the specified offset. |
int |
getLineStartOffset(int line)
Returns the start offset of the specified line. |
java.lang.String |
getLineText(int line)
Returns the text on the specified line. |
void |
getLineText(int line,
javax.swing.text.Segment segment)
Returns the specified line in a Segment . |
Marker |
getMarker(char shortcut)
Returns the marker with the specified shortcut. |
Marker |
getMarkerAtLine(int line)
Returns the first marker at the specified line, or null
if there is none. |
Marker |
getMarkerInRange(int start,
int end)
Returns the first marker within the specified range. |
java.lang.String |
getMarkerNameString()
Returns a string of all set markers, used by the status bar (eg, "a b $ % ^"). |
java.util.Vector |
getMarkers()
Returns a vector of markers. |
java.lang.String |
getMarkerStatusPrompt(java.lang.String action)
Returns the status prompt for the given marker action. |
Mode |
getMode()
Returns this buffer's edit mode. |
java.lang.String |
getName()
Returns the name of this buffer. |
Buffer |
getNext()
Returns the next buffer in the list. |
int |
getOffsetOfVirtualColumn(int line,
int column,
int[] totalVirtualWidth)
Returns the offset of a virtual column number (taking tabs into account) relative to the start of the line in question. |
javax.swing.text.Element |
getParagraphElement(int offset)
Deprecated. |
java.lang.String |
getPath()
Returns the path name of this buffer. |
Buffer |
getPrev()
Returns the previous buffer in the list. |
java.lang.Object |
getProperty(java.lang.Object name)
Returns the value of a buffer-local property. |
RE |
getRegexpProperty(java.lang.String name,
int cflags,
RESyntax syntax)
Returns the value of a property as a regular expression. |
javax.swing.text.Element[] |
getRootElements()
Deprecated. |
ParserRuleSet |
getRuleSetAtOffset(int offset)
Returns the syntax highlighting ruleset at the specified offset. |
java.lang.String |
getStringProperty(java.lang.String name)
Returns the value of a string property. |
java.lang.String |
getSymlinkPath()
If this file is a symbolic link, returns the link destination. |
int |
getTabSize()
Returns the tab size used in this buffer. |
java.lang.String |
getText(int start,
int length)
Returns the specified text range. |
void |
getText(int start,
int length,
javax.swing.text.Segment seg)
Returns the specified text range in a Segment . |
VFS |
getVFS()
Returns the virtual filesystem responsible for loading and saving this buffer. |
int |
getVirtualWidth(int line,
int column)
Returns the virtual column number (taking tabs into account) of the specified position. |
boolean |
indentLine(int lineIndex,
boolean canDecreaseIndent)
Indents the specified line. |
boolean |
indentLine(int lineIndex,
boolean canIncreaseIndent,
boolean canDecreaseIndent)
Deprecated. Use indentLine(int,boolean) instead. |
void |
indentLines(int[] lines)
Indents all specified lines. |
void |
indentLines(int start,
int end)
Indents all specified lines. |
void |
insert(int offset,
javax.swing.text.Segment seg)
Inserts a string into the buffer. |
void |
insert(int offset,
java.lang.String str)
Inserts a string into the buffer. |
void |
insertAtColumn(int line,
int col,
java.lang.String str)
Like the insert(int,String) method, but inserts the string at
the specified virtual column. |
boolean |
insertFile(View view,
java.lang.String path)
Loads a file from disk, and inserts it into this buffer. |
int |
insertIndented(int offset,
java.lang.String text)
Inserts a string into the buffer, indenting each line of the string to match the indent of the first line. |
void |
insertString(int offset,
java.lang.String str,
javax.swing.text.AttributeSet attr)
Deprecated. Call insert() instead. |
boolean |
insideCompoundEdit()
Returns if a compound edit is currently active. |
void |
invalidateCachedFoldLevels()
Invalidates all cached fold level information. |
void |
invalidateCachedScreenLineCounts()
Invalidates all cached screen line count information. |
boolean |
isClosed()
Returns true if this buffer has been closed with jEdit.closeBuffer(View,Buffer) . |
boolean |
isDirty()
Returns whether there have been unsaved changes to this buffer. |
boolean |
isEditable()
Returns true if this file is editable, false otherwise. |
boolean |
isFoldEnd(int line)
Returns if the specified line ends a fold. |
boolean |
isFoldStart(int line)
Returns if the specified line begins a fold. |
boolean |
isLoaded()
Returns true if the buffer is loaded. |
boolean |
isNewFile()
Returns whether this buffer lacks a corresponding version on disk. |
boolean |
isPerformingIO()
Returns true if the buffer is currently performing I/O. |
boolean |
isReadOnly()
Returns true if this file is read only, false otherwise. |
boolean |
isTemporary()
Returns if this is a temporary buffer. |
boolean |
isTransactionInProgress()
Returns if an undo or compound edit is currently in progress. |
boolean |
isUntitled()
Returns true if this file is 'untitled'. |
boolean |
load(View view,
boolean reload)
Loads the buffer from disk, even if it is loaded already. |
Buffer.TokenList |
markTokens(int lineIndex)
Deprecated. Use the other form of markTokens() instead |
void |
markTokens(int lineIndex,
TokenHandler tokenHandler)
Returns the syntax tokens for the specified line. |
void |
propertiesChanged()
Reloads settings from the properties. |
void |
putBooleanProperty(java.lang.String name,
boolean value)
Deprecated. Call setBooleanProperty() instead |
void |
putProperty(java.lang.Object name,
java.lang.Object value)
Deprecated. Call setProperty() instead. |
void |
readLock()
The buffer is guaranteed not to change between calls to readLock() and readUnlock() . |
void |
readUnlock()
The buffer is guaranteed not to change between calls to readLock() and readUnlock() . |
void |
redo(JEditTextArea textArea)
Redoes the most recently undone edit. |
void |
reload(View view)
Reloads the buffer from disk, asking for confirmation if the buffer has unsaved changes. |
void |
remove(int offset,
int length)
Removes the specified rang efrom the buffer. |
void |
removeAllMarkers()
Removes all defined markers. |
void |
removeBufferChangeListener(BufferChangeListener listener)
Removes a buffer change listener. |
void |
removeMarker(int line)
Removes all markers at the specified line. |
void |
removeTrailingWhiteSpace(int[] lines)
Removes trailing whitespace from all lines in the specified list. |
boolean |
save(View view,
java.lang.String path)
Saves this buffer to the specified path name, or the current path name if it's null. |
boolean |
save(View view,
java.lang.String path,
boolean rename)
Saves this buffer to the specified path name, or the current path name if it's null. |
boolean |
saveAs(View view,
boolean rename)
Prompts the user for a file to save this buffer to. |
void |
setBooleanProperty(java.lang.String name,
boolean value)
Sets a boolean property. |
void |
setDirty(boolean d)
Sets the 'dirty' (changed since last save) flag of this buffer. |
void |
setFoldHandler(FoldHandler foldHandler)
Sets the buffer's fold handler. |
void |
setIntegerProperty(java.lang.String name,
int value)
Sets an integer property. |
void |
setLastModified(long modTime)
Sets the last time jEdit modified the file on disk. |
void |
setMode()
Sets this buffer's edit mode by calling the accept() method of each registered edit mode. |
void |
setMode(Mode mode)
Sets this buffer's edit mode. |
void |
setMode(java.lang.String mode)
Sets this buffer's edit mode. |
void |
setNewFile(boolean newFile)
Sets the new file flag. |
void |
setProperty(java.lang.String name,
java.lang.Object value)
Sets the value of a buffer-local property. |
void |
setReadOnly(boolean readOnly)
Sets the read only flag. |
void |
setStringProperty(java.lang.String name,
java.lang.String value)
Sets a string property. |
void |
setWaitSocket(java.net.Socket waitSocket)
This socket is closed when the buffer is closed. |
void |
shiftIndentLeft(int[] lines)
Shifts the indent of each line in the specified list to the left. |
void |
shiftIndentRight(int[] lines)
Shifts the indent of each line in the specified list to the right. |
void |
toggleLineSeparator(View view)
Toggles the line separator between the three available settings. |
void |
toggleWordWrap(View view)
Toggles word wrap between the three available modes. |
java.lang.String |
toString()
Returns a string representation of this buffer. |
void |
undo(JEditTextArea textArea)
Undoes the most recent edit. |
void |
unsetProperty(java.lang.String name)
Clears the value of a buffer-local property. |
void |
writeLock()
Attempting to obtain read lock will block between calls to writeLock() and writeUnlock() . |
void |
writeUnlock()
Attempting to obtain read lock will block between calls to writeLock() and writeUnlock() . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String LINESEP
public static final java.lang.String BACKED_UP
public static final java.lang.String CARET
public static final java.lang.String SELECTION
public static final java.lang.String SCROLL_VERT
public static final java.lang.String SCROLL_HORIZ
public static final java.lang.String ENCODING
public static final java.lang.String ENCODING_AUTODETECT
public static final java.lang.String TRAILING_EOL
public static final java.lang.String GZIPPED
public static final int FILE_NOT_CHANGED
public static final int FILE_CHANGED
public static final int FILE_DELETED
public static final int NORMAL_PRIORITY
public static final int HIGH_PRIORITY
Method Detail |
public void reload(View view)
view
- The viewpublic boolean load(View view, boolean reload)
view
- The viewreload
- If true, user will not be asked to recover autosave
file, if anypublic boolean insertFile(View view, java.lang.String path)
view
- The viewpublic void autosave()
public boolean saveAs(View view, boolean rename)
view
- The viewrename
- True if the buffer's path should be changed, false
if only a copy should be saved to the specified filenamepublic boolean save(View view, java.lang.String path)
view
- The viewpath
- The path name to save the buffer to, or null to use
the existing pathpublic boolean save(View view, java.lang.String path, boolean rename)
view
- The viewpath
- The path name to save the buffer to, or null to use
the existing pathrename
- True if the buffer's path should be changed, false
if only a copy should be saved to the specified filenamepublic int checkFileStatus(View view)
NOT_CHANGED
, CHANGED
, or
DELETED
.public long getLastModified()
public void setLastModified(long modTime)
modTime
- The new modification timepublic VFS getVFS()
public java.io.File getAutosaveFile()
public java.lang.String getName()
public java.lang.String getPath()
public java.lang.String getSymlinkPath()
public java.lang.String getDirectory()
public boolean isClosed()
jEdit.closeBuffer(View,Buffer)
.
This method is thread-safe.
public boolean isLoaded()
public boolean isPerformingIO()
public boolean isNewFile()
public void setNewFile(boolean newFile)
newFile
- The new file flagpublic boolean isUntitled()
public boolean isDirty()
public boolean isReadOnly()
public boolean isEditable()
public void setReadOnly(boolean readOnly)
readOnly
- The read only flagpublic void setDirty(boolean d)
public boolean isTemporary()
jEdit.openTemporary(View,String,String,boolean)
,
jEdit.commitTemporary(Buffer)
public javax.swing.Icon getIcon()
public void readLock()
readLock()
and readUnlock()
.
public void readUnlock()
readLock()
and readUnlock()
.
public void writeLock()
writeLock()
and writeUnlock()
.
public void writeUnlock()
writeLock()
and writeUnlock()
.
public int getLength()
public int getLineCount()
public int getLineOfOffset(int offset)
offset
- The offsetpublic int getLineStartOffset(int line)
line
- The line
public int getLineEndOffset(int line)
line
- The line
public int getLineLength(int line)
line
- The linepublic void invalidateCachedScreenLineCounts()
public java.lang.String getLineText(int line)
line
- The line
public void getLineText(int line, javax.swing.text.Segment segment)
Segment
.
Using a
This method is thread-safe.
line
- The linepublic java.lang.String getText(int start, int length)
start
- The start offsetlength
- The number of characters to getpublic void getText(int start, int length, javax.swing.text.Segment seg)
Segment
.
Using a
This method is thread-safe.
start
- The start offsetlength
- The number of characters to getseg
- The segment to copy the text topublic void insert(int offset, java.lang.String str)
offset
- The offsetstr
- The stringpublic void insert(int offset, javax.swing.text.Segment seg)
offset
- The offsetseg
- The segmentpublic void remove(int offset, int length)
offset
- The start offsetlength
- The number of characters to removepublic void undo(JEditTextArea textArea)
public void redo(JEditTextArea textArea)
public boolean isTransactionInProgress()
BufferChangeListener.transactionComplete(Buffer)
buffer event will get fired.
public void beginCompoundEdit()
endCompoundEdit()
are called will be merged
into one. This can be used to make a complex operation
undoable in one step. Nested calls to
beginCompoundEdit()
behave as expected,
requiring the same number of endCompoundEdit()
calls to end the edit.
endCompoundEdit()
public void endCompoundEdit()
beginCompoundEdit()
was called can now
be undone in one step by calling undo(JEditTextArea)
.
beginCompoundEdit()
public boolean insideCompoundEdit()
public void addBufferChangeListener(BufferChangeListener listener, int priority)
listener
- The listenerpriority
- Listeners with HIGH_PRIORITY get the event before
listeners with NORMAL_PRIORITYpublic void addBufferChangeListener(BufferChangeListener listener)
listener
- The listenerpublic void removeBufferChangeListener(BufferChangeListener listener)
listener
- The listenerpublic BufferChangeListener[] getBufferChangeListeners()
public void propertiesChanged()
syntax
or folding
buffer-local properties are changed.
public int getTabSize()
getProperty("tabSize")
.
This method is thread-safe.
public int getIndentSize()
getProperty("indentSize")
.
This method is thread-safe.
public java.lang.Object getProperty(java.lang.Object name)
Using this method is generally discouraged, because it returns an
Object
which must be cast to another type
in order to be useful, and this can cause problems if the object
is of a different type than what the caller expects.
The following methods should be used instead:
getStringProperty(String)
getBooleanProperty(String)
getIntegerProperty(String,int)
getRegexpProperty(String,int,gnu.regexp.RESyntax)
name
- The property name. For backwards compatibility, this
is an Object
, not a String
.public void setProperty(java.lang.String name, java.lang.Object value)
name
- The property namevalue
- The property valuepublic void unsetProperty(java.lang.String name)
name
- The property namepublic java.lang.String getStringProperty(java.lang.String name)
name
- The property namepublic void setStringProperty(java.lang.String name, java.lang.String value)
name
- The property namevalue
- The valuepublic boolean getBooleanProperty(java.lang.String name)
name
- The property namepublic void setBooleanProperty(java.lang.String name, boolean value)
name
- The property namevalue
- The valuepublic int getIntegerProperty(java.lang.String name, int defaultValue)
name
- The property namepublic void setIntegerProperty(java.lang.String name, int value)
name
- The property namevalue
- The valuepublic RE getRegexpProperty(java.lang.String name, int cflags, RESyntax syntax) throws REException
name
- The property namecflags
- Regular expression compilation flagssyntax
- Regular expression syntax
REException
public ParserRuleSet getRuleSetAtOffset(int offset)
public KeywordMap getKeywordMapAtOffset(int offset)
offset
- The offsetpublic java.lang.String getContextSensitiveProperty(int offset, java.lang.String name)
offset
- The offsetname
- The property namepublic void toggleWordWrap(View view)
view
- We show a message in the view's status barpublic void toggleLineSeparator(View view)
view
- We show a message in the view's status barpublic Mode getMode()
public void setMode(java.lang.String mode)
mode
- The mode namepublic void setMode(Mode mode)
mode
- The modepublic void setMode()
public void markTokens(int lineIndex, TokenHandler tokenHandler)
lineIndex
- The line numbertokenHandler
- The token handler that will receive the syntax
tokenspublic void removeTrailingWhiteSpace(int[] lines)
lines
- The line numberspublic void shiftIndentLeft(int[] lines)
lines
- The line numberspublic void shiftIndentRight(int[] lines)
lines
- The line numberspublic void indentLines(int start, int end)
start
- The first line to indentend
- The last line to indentpublic void indentLines(int[] lines)
lines
- The line numberspublic boolean indentLine(int lineIndex, boolean canIncreaseIndent, boolean canDecreaseIndent)
indentLine(int,boolean)
instead.
public boolean indentLine(int lineIndex, boolean canDecreaseIndent)
lineIndex
- The line number to indentcanDecreaseIndent
- If true, the indent can be decreased as a
result of this. Set this to false for Tab key.
public int getCurrentIndentForLine(int lineIndex, int[] whitespaceChars)
lineIndex
- The line numberwhitespaceChars
- If this is non-null, the number of whitespace
characters is stored at the 0 indexpublic int getIdealIndentForLine(int lineIndex)
lineIndex
- The line numberpublic int getVirtualWidth(int line, int column)
line
- The line numbercolumn
- The column numberpublic int getOffsetOfVirtualColumn(int line, int column, int[] totalVirtualWidth)
line
- The line numbercolumn
- The virtual column numbertotalVirtualWidth
- If this array is non-null, the total
virtual width will be stored in its first location if this method
returns -1.
public void insertAtColumn(int line, int col, java.lang.String str)
insert(int,String)
method, but inserts the string at
the specified virtual column. Inserts spaces as appropriate if
the line is shorter than the column.
line
- The line numbercol
- The virtual column numberstr
- The stringpublic int insertIndented(int offset, java.lang.String text)
offset
- The offsettext
- The text
public void putProperty(java.lang.Object name, java.lang.Object value)
setProperty()
instead.
public void putBooleanProperty(java.lang.String name, boolean value)
setBooleanProperty()
instead
public Buffer.TokenList markTokens(int lineIndex)
markTokens()
instead
public javax.swing.text.Element[] getRootElements()
public javax.swing.text.Element getParagraphElement(int offset)
public javax.swing.text.Element getDefaultRootElement()
getLineOfOffset()
,
getLineStartOffset()
, and
getLineEndOffset()
instead.
public void insertString(int offset, java.lang.String str, javax.swing.text.AttributeSet attr)
insert()
instead.
public java.io.File getFile()
getPath()
instead.
public int getCurrentIdentForLine(int lineIndex, int[] whitespaceChars)
public boolean isFoldStart(int line)
public boolean isFoldEnd(int line)
public void invalidateCachedFoldLevels()
public int getFoldLevel(int line)
line
- A physical line indexpublic int[] getFoldAtLine(int line)
line
- The line numberpublic FoldHandler getFoldHandler()
public void setFoldHandler(FoldHandler foldHandler)
public javax.swing.text.Position createPosition(int offset)
offset
- The offsetpublic java.util.Vector getMarkers()
public java.lang.String getMarkerStatusPrompt(java.lang.String action)
actions.xml
.
public java.lang.String getMarkerNameString()
public void addOrRemoveMarker(char shortcut, int pos)
pos
- The position of the markershortcut
- The shortcut ('\0' if none)public void addMarker(char shortcut, int pos)
pos
- The position of the markershortcut
- The shortcut ('\0' if none)public Marker getMarkerInRange(int start, int end)
start
- The start offsetend
- The end offsetpublic Marker getMarkerAtLine(int line)
null
if there is none.
line
- The line numberpublic void removeMarker(int line)
line
- The line numberpublic void removeAllMarkers()
public Marker getMarker(char shortcut)
shortcut
- The shortcutpublic void setWaitSocket(java.net.Socket waitSocket)
public Buffer getNext()
public Buffer getPrev()
public int getIndex()
public java.lang.String toString()
public LineManager _getLineManager()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |