public class Buffer extends JEditBuffer
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:
JEditBuffer.PropValue| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
BACKED_UP
Backed up property.
|
static java.lang.String |
CARET
Caret info properties.
|
static java.lang.String |
CARET_POSITIONED |
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 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
Stores a List of
Selection instances. |
static java.lang.String |
TRAILING_EOL
This property is set to 'true' if the file has a trailing newline.
|
columnBlockLock, contextInsensitive, elasticTabstopsOn, ENCODING, HIGH_PRIORITY, LINESEP, mode, NORMAL_PRIORITY, tokenMarker, undoMgr| Modifier and Type | Method and Description |
|---|---|
void |
addBufferUndoListener(BufferUndoListener listener)
Adds a buffer undo 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.
|
int |
checkFileStatus(View view)
Check if the buffer has changed on disk.
|
protected void |
fireBeginRedo() |
protected void |
fireBeginUndo() |
protected void |
fireEndRedo() |
protected void |
fireEndUndo() |
boolean |
getAutoReload()
Returns the status of the AUTORELOAD flag
If true, reload changed files automatically
|
boolean |
getAutoReloadDialog()
Returns the status of the AUTORELOAD_DIALOG flag
If true, prompt for reloading or notify user
when the file has changed on disk
|
java.io.File |
getAutosaveFile()
Returns the autosave file for this buffer.
|
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).
|
java.lang.Object |
getDefaultProperty(java.lang.String name) |
java.lang.String |
getDirectory()
Returns the directory containing this buffer.
|
java.io.File |
getFile()
Deprecated.
Do not call this method, use
getPath()
instead. |
javax.swing.Icon |
getIcon()
Returns this buffer's icon.
|
int |
getIndex()
Returns the position of this buffer in the buffer list.
|
long |
getLastModified()
Returns the last time jEdit modified the file on disk.
|
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<Marker> |
getMarkers()
Returns a vector of markers.
|
static java.lang.String |
getMarkersPath(VFS vfs,
java.lang.String path)
Returns the path for this buffer's markers file
|
java.lang.String |
getMarkerStatusPrompt(java.lang.String action)
Returns the status prompt for the given marker action.
|
java.lang.String |
getName()
Returns the name of this buffer.
|
Buffer |
getNext()
Returns the next buffer in the list.
|
java.lang.String |
getPath()
Returns the path name of this buffer.
|
java.lang.String |
getPath(java.lang.Boolean shortVersion) |
Buffer |
getPrev()
Returns the previous buffer in the list.
|
java.lang.String |
getSymlinkPath()
If this file is a symbolic link, returns the link destination.
|
VFS |
getVFS()
Returns the virtual filesystem responsible for loading and
saving this buffer.
|
boolean |
insertFile(View view,
java.lang.String path)
Loads a file from disk, and inserts it into this buffer.
|
boolean |
isClosed()
Returns true if this buffer has been closed with
jEdit.closeBuffer(View,Buffer). |
boolean |
isLoaded()
Returns true if the buffer is loaded.
|
boolean |
isNewFile()
Returns whether this buffer lacks a corresponding version on disk.
|
boolean |
isTemporary()
Returns if this is a temporary buffer.
|
boolean |
isUntitled()
Returns true if this file is 'untitled'.
|
boolean |
load(View view,
boolean reload)
Loads the buffer from disk.
|
boolean |
markersChanged()
Return true when markers have changed and the markers file needs
to be updated
|
protected TokenMarker.LineContext |
markTokens(javax.swing.text.Segment seg,
TokenMarker.LineContext prevContext,
TokenHandler _tokenHandler) |
void |
propertiesChanged()
Reloads settings from the properties.
|
void |
reload(View view)
Reloads the buffer from disk, asking for confirmation if the buffer
has unsaved changes.
|
void |
removeAllMarkers()
Removes all defined markers.
|
void |
removeAutosaveFile()
Remove the autosave file.
|
void |
removeBufferUndoListener(BufferUndoListener listener)
Removes a buffer undo listener.
|
void |
removeMarker(int line)
Removes all markers at the specified line.
|
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 |
save(View view,
java.lang.String path,
boolean rename,
boolean disableFileStatusCheck)
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 |
setAutoReload(boolean value)
Sets the status of the AUTORELOAD flag
|
void |
setAutoReloadDialog(boolean value)
Sets the status of the AUTORELOAD_DIALOG flag
|
void |
setDirty(boolean d)
Sets the 'dirty' (changed since last save) flag of this buffer.
|
void |
setLastModified(long modTime)
Sets the last time jEdit modified the file on disk.
|
void |
setMarkersChanged(boolean changed)
Sets/unsets the MARKERS_CHANGED flag
|
void |
setMode()
Sets this buffer's edit mode by calling the accept() method
of each registered edit mode.
|
void |
setNewFile(boolean newFile)
Sets the new file flag.
|
void |
setWaitSocket(java.net.Socket waitSocket)
This socket is closed when the buffer is closed.
|
void |
toggleAutoIndent(View view)
Toggles automatic indentation on and off.
|
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.
|
boolean |
updateMarkersFile(View view)
Save the markers file, or delete it when there are mo markers left
Handling markers is now independent from saving the buffer.
|
addBufferListener, addBufferListener, beginCompoundEdit, canRedo, canUndo, createPosition, endCompoundEdit, fireBufferLoaded, fireContentInserted, fireContentRemoved, fireFoldHandlerChanged, fireFoldLevelChanged, firePreContentInserted, firePreContentRemoved, fireTransactionComplete, getBooleanProperty, getBooleanProperty, getBufferListeners, getColumnBlock, getCurrentIndentForLine, getFoldAtLine, getFoldHandler, getFoldLevel, getIdealIndentForLine, getIndentSize, getIntegerProperty, getKeywordMapAtOffset, getLength, getLineCount, getLineEndOffset, getLineLength, getLineOfOffset, getLineSegment, getLineStartOffset, getLineText, getLineText, getLineText, getMode, getOffsetOfVirtualColumn, getPatternProperty, getPriorNonEmptyLine, getProperty, getRuleSetAtOffset, getSegment, getStringProperty, getTabSize, getTabStopPosition, getText, getText, getText, getTokenMarker, getUndoId, getVirtualWidth, indentLine, indentLines, indentLines, indentUsingElasticTabstops, insert, insert, insert, insertAtColumn, insertIndented, insideCompoundEdit, invalidateCachedFoldLevels, invalidateFoldLevels, isContextInsensitive, isDirty, isEditable, isElectricKey, isFileReadOnly, isFoldEnd, isFoldStart, isLoading, isPerformingIO, isReadOnly, isTransactionInProgress, isUndoInProgress, loadText, markTokens, parseBufferLocalProperties, readLock, readUnlock, redo, remove, removeBufferListener, removeTrailingWhiteSpace, resetCachedProperties, setBooleanProperty, setContextInsensitive, setDefaultProperty, setFileReadOnly, setFoldHandler, setIntegerProperty, setLoading, setMode, setMode, setMode, setPerformingIO, setProperty, setReadOnly, setStringProperty, setTokenMarker, setUndoLimit, shiftIndentLeft, shiftIndentRight, simpleIndentLine, undo, unsetProperty, updateColumnBlocks, writeLock, writeUnlockpublic static final java.lang.String BACKED_UP
public static final java.lang.String CARET
public static final java.lang.String CARET_POSITIONED
public static final java.lang.String SELECTION
Selection instances.public static final java.lang.String SCROLL_VERT
public static final java.lang.String SCROLL_HORIZ
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 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 viewpath - the path of the file to insertpublic 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 usepublic 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 boolean save(View view, java.lang.String path, boolean rename, boolean disableFileStatusCheck)
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 filenamedisableFileStatusCheck - Disables file status checking
regardless of the state of the checkFileStatus propertypublic int checkFileStatus(View view)
FILE_NOT_CHANGED, FILE_CHANGED, or
FILE_DELETED.public long getLastModified()
public void setLastModified(long modTime)
modTime - The new modification timepublic boolean getAutoReload()
public void setAutoReload(boolean value)
value - # If true, reload changed files automaticallypublic boolean getAutoReloadDialog()
public void setAutoReloadDialog(boolean value)
value - # If true, prompt for reloading or notify user
when the file has changed on diskpublic VFS getVFS()
public java.io.File getAutosaveFile()
public void removeAutosaveFile()
public java.lang.String getName()
public java.lang.String getPath()
public java.lang.String getPath(java.lang.Boolean shortVersion)
shortVersion - if true, replaces home path with ~/ on unixpublic 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 isNewFile()
public void setNewFile(boolean newFile)
newFile - The new file flagpublic boolean isUntitled()
public void setDirty(boolean d)
setDirty in class JEditBufferpublic boolean isTemporary()
jEdit.openTemporary(View,String,String,boolean),
jEdit.commitTemporary(Buffer)public javax.swing.Icon getIcon()
public void propertiesChanged()
syntax or folding
buffer-local properties are changed.propertiesChanged in class JEditBufferpublic java.lang.Object getDefaultProperty(java.lang.String name)
getDefaultProperty in class JEditBufferpublic void toggleWordWrap(View view)
view - We show a message in the view's status barpublic void toggleAutoIndent(View view)
view - This view's status bar will display the messagepublic void toggleLineSeparator(View view)
view - We show a message in the view's status barpublic java.lang.String getContextSensitiveProperty(int offset,
java.lang.String name)
getContextSensitiveProperty in class JEditBufferoffset - The offsetname - The property namepublic void setMode()
@Deprecated public java.io.File getFile()
getPath()
instead.public java.util.Vector<Marker> 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 static java.lang.String getMarkersPath(VFS vfs, java.lang.String path)
vfs - The appropriate VFSpath - the path of the buffer, it can be different from the field
when using save-aspublic boolean updateMarkersFile(View view)
view - The current viewpublic boolean markersChanged()
public void setMarkersChanged(boolean changed)
public void setWaitSocket(java.net.Socket waitSocket)
public Buffer getNext()
public Buffer getPrev()
public int getIndex()
public java.lang.String toString()
toString in class java.lang.Objectpublic void addBufferUndoListener(BufferUndoListener listener)
listener - The listenerpublic void removeBufferUndoListener(BufferUndoListener listener)
listener - The listenerprotected TokenMarker.LineContext markTokens(javax.swing.text.Segment seg, TokenMarker.LineContext prevContext, TokenHandler _tokenHandler)
markTokens in class JEditBufferprotected void fireBeginUndo()
fireBeginUndo in class JEditBufferprotected void fireEndUndo()
fireEndUndo in class JEditBufferprotected void fireBeginRedo()
fireBeginRedo in class JEditBufferprotected void fireEndRedo()
fireEndRedo in class JEditBuffer