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.
|
void |
autosave(boolean force)
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() |
boolean |
getAutoReloadDialog() |
java.io.File |
getAutosaveFile() |
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() |
java.io.File |
getFile()
Deprecated.
Do not call this method, use
getPath()
instead. |
javax.swing.Icon |
getIcon() |
int |
getIndex() |
long |
getLastModified() |
Marker |
getMarker(char shortcut) |
Marker |
getMarkerAtLine(int line) |
Marker |
getMarkerInRange(int start,
int end) |
java.lang.String |
getMarkerNameString() |
java.util.Vector<Marker> |
getMarkers() |
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) |
java.lang.String |
getName() |
Buffer |
getNext() |
java.lang.String |
getPath() |
java.lang.String |
getPath(java.lang.Boolean shortVersion) |
Buffer |
getPrev() |
java.lang.String |
getSymlinkPath() |
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() |
boolean |
isLoaded() |
boolean |
isNewFile() |
boolean |
isTemporary() |
boolean |
isUntitled() |
boolean |
load(View view,
boolean reload)
Loads the buffer from disk.
|
boolean |
markersChanged() |
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.
|
protected void |
setUntitled(boolean untitled) |
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, getLineContext, 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, writeUnlock
public 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 void autosave(boolean force)
force
- save even if AUTOSAVE_DIRTY not setpublic 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)
view
- the ViewFILE_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()
protected void setUntitled(boolean untitled)
untitled
- untitled value to setpublic void setDirty(boolean d)
setDirty
in class JEditBuffer
d
- Sets the 'dirty' (changed since last save) flag of this buffer.public 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 JEditBuffer
public java.lang.Object getDefaultProperty(java.lang.String name)
getDefaultProperty
in class JEditBuffer
public 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 JEditBuffer
offset
- 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)
action
- some actionactions.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)
line
- The line numbernull
if there is none.public 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)
changed
- changedpublic void setWaitSocket(java.net.Socket waitSocket)
waitSocket
- the socketpublic Buffer getNext()
public Buffer getPrev()
public int getIndex()
public java.lang.String toString()
toString
in class java.lang.Object
public 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 JEditBuffer
protected void fireBeginUndo()
fireBeginUndo
in class JEditBuffer
protected void fireEndUndo()
fireEndUndo
in class JEditBuffer
protected void fireBeginRedo()
fireBeginRedo
in class JEditBuffer
protected void fireEndRedo()
fireEndRedo
in class JEditBuffer