Package org.gjt.sp.jedit
Class Buffer
- java.lang.Object
-
- org.gjt.sp.jedit.buffer.JEditBuffer
-
- org.gjt.sp.jedit.Buffer
-
public class Buffer extends JEditBuffer
ABufferrepresents 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
buffervariable.This class does not have a public constructor. Buffers can be opened and closed using methods in the
jEditclass.This class is partially thread-safe, however you must pay attention to two very important guidelines:
- Operations such as insert() and remove(), undo(), change Buffer data in a writeLock(), and must be called from the AWT thread.
- When accessing the buffer from another thread, you must call readLock() before and readUnLock() after, if you plan on performing more than one read, to ensure that the buffer contents are not changed by the AWT thread for the duration of the lock. Only methods whose descriptions specify thread safety can be invoked from other threads.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.gjt.sp.jedit.buffer.JEditBuffer
JEditBuffer.PropValue
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBACKED_UPBacked up property.static java.lang.StringCARETCaret info properties.static java.lang.StringCARET_POSITIONEDstatic java.lang.StringENCODING_AUTODETECTShould jEdit try to set the encoding based on a UTF8, UTF16 or XML signature at the beginning of the file?static intFILE_CHANGEDstatic intFILE_DELETEDstatic intFILE_NOT_CHANGEDstatic java.lang.StringGZIPPEDThis property is set to 'true' if the file should be GZipped.static java.lang.StringSCROLL_HORIZstatic java.lang.StringSCROLL_VERTThis 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.StringSELECTIONStores a List ofSelectioninstances.static java.lang.StringTRAILING_EOLThis property is set to 'true' if the file has a trailing newline.-
Fields inherited from class org.gjt.sp.jedit.buffer.JEditBuffer
columnBlockLock, contextInsensitive, elasticTabstopsOn, ENCODING, HIGH_PRIORITY, LINESEP, mode, NORMAL_PRIORITY, tokenMarker, undoMgr
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddBufferUndoListener(BufferUndoListener listener)Adds a buffer undo listener.voidaddMarker(char shortcut, int pos)Adds a marker to this buffer.voidaddOrRemoveMarker(char shortcut, int pos)If a marker is set on the line of the position, it is removed.voidautosave()Autosaves this buffer.voidautosave(boolean force)Autosaves this buffer.intcheckFileStatus(View view)Check if the buffer has changed on disk.voidclose()protected voidfireBeginRedo()protected voidfireBeginUndo()protected voidfireEndRedo()protected voidfireEndUndo()booleangetAutoReload()booleangetAutoReloadDialog()java.io.FilegetAutosaveFile()java.lang.StringgetContextSensitiveProperty(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.ObjectgetDefaultProperty(java.lang.String name)java.lang.StringgetDirectory()java.io.FilegetFile()Deprecated.Do not call this method, usegetPath()instead.javax.swing.IcongetIcon()intgetIndex()longgetLastModified()MarkergetMarker(char shortcut)MarkergetMarkerAtLine(int line)MarkergetMarkerInRange(int start, int end)java.lang.StringgetMarkerNameString()java.util.Vector<Marker>getMarkers()static java.lang.StringgetMarkersPath(VFS vfs, java.lang.String path)Returns the path for this buffer's markers filejava.lang.StringgetMarkerStatusPrompt(java.lang.String action)java.lang.StringgetName()BuffergetNext()java.lang.StringgetPath()java.lang.StringgetPath(java.lang.Boolean shortVersion)BuffergetPrev()java.lang.StringgetSymlinkPath()VFSgetVFS()Returns the virtual filesystem responsible for loading and saving this buffer.booleaninsertFile(View view, java.lang.String path)Loads a file from disk, and inserts it into this buffer.booleanisBackup()booleanisClosed()booleanisEditable()booleanisLoaded()booleanisLocked()booleanisNewFile()booleanisTemporary()booleanisTitled()booleanisUntitled()booleanload(View view, boolean reload)Loads the buffer from disk.booleanmarkersChanged()protected TokenMarker.LineContextmarkTokens(javax.swing.text.Segment seg, TokenMarker.LineContext prevContext, TokenHandler _tokenHandler)voidpropertiesChanged()Reloads settings from the properties.voidreload(View view)Reloads the buffer from disk, asking for confirmation if the buffer has unsaved changes.voidremoveAllMarkers()Removes all defined markers.voidremoveAutosaveFile()Remove the autosave file.voidremoveBufferUndoListener(BufferUndoListener listener)Removes a buffer undo listener.voidremoveMarker(int line)Removes all markers at the specified line.booleansave(View view, java.lang.String path)Saves this buffer to the specified path name, or the current path name if it's null.booleansave(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.booleansave(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.booleansaveAs(View view, boolean rename)Prompts the user for a file to save this buffer to.voidsetAutoReload(boolean value)Sets the status of the AUTORELOAD flagvoidsetAutoReloadDialog(boolean value)Sets the status of the AUTORELOAD_DIALOG flagvoidsetDirty(boolean d)Sets the 'dirty' (changed since last save) flag of this buffer.voidsetLastModified(long modTime)Sets the last time jEdit modified the file on disk.voidsetLocked(boolean locked)Changes locked state of the buffer.voidsetMarkersChanged(boolean changed)Sets/unsets the MARKERS_CHANGED flagvoidsetMode()Sets this buffer's edit mode by calling the accept() method of each registered edit mode.voidsetNewFile(boolean newFile)Sets the new file flag.voidsetNext(Buffer next)voidsetPrev(Buffer prev)protected voidsetUntitled(boolean untitled)voidsetWaitSocket(java.net.Socket waitSocket)This socket is closed when the buffer is closed.voidtoggleAutoIndent(View view)Toggles automatic indentation on and off.voidtoggleLineSeparator(View view)Toggles the line separator between the three available settings.voidtoggleLocked(View view)Toggles locked state of the buffer.voidtoggleWordWrap(View view)Toggles word wrap between the three available modes.java.lang.StringtoString()Returns a string representation of this buffer.booleanupdateMarkersFile(View view)Save the markers file, or delete it when there are mo markers left Handling markers is now independent from saving the buffer.-
Methods inherited from class org.gjt.sp.jedit.buffer.JEditBuffer
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, hasProperty, indentLine, indentLines, indentLines, indentUsingElasticTabstops, insert, insert, insert, insertAtColumn, insertIndented, insideCompoundEdit, invalidateCachedFoldLevels, invalidateFoldLevels, isContextInsensitive, isDirty, isElectricKey, isFileReadOnly, isFoldEnd, isFoldStart, isLoading, isPerformingIO, isReadOnly, isTransactionInProgress, isUndoInProgress, loadText, markTokens, parseBufferLocalProperties, readLock, readUnlock, redo, remove, removeBufferListener, removeTrailingWhiteSpace, resetCachedProperties, setBooleanProperty, setContextInsensitive, setDefaultProperty, setEditable, setFileReadOnly, setFoldHandler, setIntegerProperty, setLoading, setMode, setMode, setMode, setPerformingIO, setProperty, setReadOnly, setStringProperty, setTokenMarker, setUndoLimit, shiftIndentLeft, shiftIndentRight, simpleIndentLine, undo, unsetProperty, updateColumnBlocks, writeLock, writeUnlock
-
-
-
-
Field Detail
-
BACKED_UP
public static final java.lang.String BACKED_UP
Backed up property.- Since:
- jEdit 3.2pre2
- See Also:
- Constant Field Values
-
CARET
public static final java.lang.String CARET
Caret info properties.- Since:
- jEdit 3.2pre1
- See Also:
- Constant Field Values
-
CARET_POSITIONED
public static final java.lang.String CARET_POSITIONED
- See Also:
- Constant Field Values
-
SELECTION
public static final java.lang.String SELECTION
Stores a List ofSelectioninstances.- See Also:
- Constant Field Values
-
SCROLL_VERT
public static final 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)- See Also:
- Constant Field Values
-
SCROLL_HORIZ
public static final java.lang.String SCROLL_HORIZ
- See Also:
- Constant Field Values
-
ENCODING_AUTODETECT
public static final 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?- See Also:
- Constant Field Values
-
TRAILING_EOL
public static final java.lang.String TRAILING_EOL
This property is set to 'true' if the file has a trailing newline.- Since:
- jEdit 4.0pre1
- See Also:
- Constant Field Values
-
GZIPPED
public static final java.lang.String GZIPPED
This property is set to 'true' if the file should be GZipped.- Since:
- jEdit 4.0pre4
- See Also:
- Constant Field Values
-
FILE_NOT_CHANGED
public static final int FILE_NOT_CHANGED
- See Also:
- Constant Field Values
-
FILE_CHANGED
public static final int FILE_CHANGED
- See Also:
- Constant Field Values
-
FILE_DELETED
public static final int FILE_DELETED
- See Also:
- Constant Field Values
-
-
Method Detail
-
reload
public void reload(View view)
Reloads the buffer from disk, asking for confirmation if the buffer has unsaved changes.- Parameters:
view- The view- Since:
- jEdit 2.7pre2
-
load
public boolean load(View view, boolean reload)
Loads the buffer from disk.- Parameters:
view- The viewreload- If true, user will not be asked to recover autosave file, if any- Returns:
- true if loaded
- Since:
- 2.5pre1
-
insertFile
public boolean insertFile(View view, java.lang.String path)
Loads a file from disk, and inserts it into this buffer.- Parameters:
view- The viewpath- the path of the file to insert- Returns:
- true if the file was inserted
- Since:
- 4.0pre1
-
autosave
public void autosave()
Autosaves this buffer.
-
autosave
public void autosave(boolean force)
Autosaves this buffer.- Parameters:
force- save even if AUTOSAVE_DIRTY not set- Since:
- jEdit 5.5pre1
-
saveAs
public boolean saveAs(View view, boolean rename)
Prompts the user for a file to save this buffer to.- Parameters:
view- The viewrename- True if the buffer's path should be changed, false if only a copy should be saved to the specified filename- Returns:
- true if the buffer was successfully saved
- Since:
- jEdit 2.6pre5
-
save
public 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.- Parameters:
view- The viewpath- The path name to save the buffer to, or null to use- Returns:
- true if the buffer was successfully saved the existing path
-
save
public 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.- Parameters:
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 filename- Returns:
- true if the buffer was successfully saved
- Since:
- jEdit 2.6pre5
-
save
public 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.- Parameters:
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 property- Returns:
- true if the buffer was successfully saved
-
checkFileStatus
public int checkFileStatus(View view)
Check if the buffer has changed on disk.- Parameters:
view- the View- Returns:
- One of
FILE_NOT_CHANGED,FILE_CHANGED, orFILE_DELETED. - Since:
- jEdit 4.2pre1
-
getLastModified
public long getLastModified()
- Returns:
- the last time jEdit modified the file on disk. This method is thread-safe.
-
setLastModified
public void setLastModified(long modTime)
Sets the last time jEdit modified the file on disk.- Parameters:
modTime- The new modification time
-
getAutoReload
public boolean getAutoReload()
- Returns:
- the status of the AUTORELOAD flag If true, reload changed files automatically
-
setAutoReload
public void setAutoReload(boolean value)
Sets the status of the AUTORELOAD flag- Parameters:
value- # If true, reload changed files automatically
-
getAutoReloadDialog
public 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
-
setAutoReloadDialog
public void setAutoReloadDialog(boolean value)
Sets the status of the AUTORELOAD_DIALOG flag- Parameters:
value- # If true, prompt for reloading or notify user when the file has changed on disk
-
getVFS
public VFS getVFS()
Returns the virtual filesystem responsible for loading and saving this buffer. This method is thread-safe.- Returns:
- the VFS
-
getAutosaveFile
public java.io.File getAutosaveFile()
- Returns:
- the autosave file for this buffer. This may be null if the file is non-local.
-
removeAutosaveFile
public void removeAutosaveFile()
Remove the autosave file.- Since:
- jEdit 4.3pre12
-
getName
public java.lang.String getName()
- Returns:
- the name of this buffer. This method is thread-safe.
-
getPath
public java.lang.String getPath()
- Returns:
- the path name of this buffer. This method is thread-safe.
-
getPath
public java.lang.String getPath(java.lang.Boolean shortVersion)
- Parameters:
shortVersion- if true, replaces home path with ~/ on unix- Returns:
- the path
-
getSymlinkPath
public java.lang.String getSymlinkPath()
- Returns:
- If this file is a symbolic link, returns the link destination. Otherwise returns the file's path. This method is thread-safe.
- Since:
- jEdit 4.2pre1
-
getDirectory
public java.lang.String getDirectory()
- Returns:
- the directory containing this buffer.
- Since:
- jEdit 4.1pre11
-
isClosed
public boolean isClosed()
- Returns:
- true if this buffer has been closed with
jEdit.closeBuffer(View,Buffer). This method is thread-safe.
-
isLoaded
public boolean isLoaded()
- Returns:
- true if the buffer is loaded. This method is thread-safe.
-
isNewFile
public boolean isNewFile()
- Returns:
- whether this buffer lacks a corresponding version on disk. This method is thread-safe.
-
setNewFile
public void setNewFile(boolean newFile)
Sets the new file flag.- Parameters:
newFile- The new file flag
-
isUntitled
public boolean isUntitled()
- Returns:
- true if this file is 'untitled'. This method is thread-safe.
-
isTitled
public boolean isTitled()
- Returns:
- true if this file is not'untitled'. This method is thread-safe.
- Since:
- jEdit 5.6pre1
-
setUntitled
protected void setUntitled(boolean untitled)
- Parameters:
untitled- untitled value to set- Since:
- jEdit 5.5pre1
-
setDirty
public void setDirty(boolean d)
Sets the 'dirty' (changed since last save) flag of this buffer.- Overrides:
setDirtyin classJEditBuffer- Parameters:
d- Sets the 'dirty' (changed since last save) flag of this buffer.
-
isTemporary
public boolean isTemporary()
- Returns:
- if this is a temporary buffer. This method is thread-safe.
- Since:
- jEdit 2.2pre7
- See Also:
jEdit.openTemporary(View,String,String,boolean),jEdit.commitTemporary(Buffer)
-
isBackup
public boolean isBackup()
- Returns:
- if this buffer most probably contains backup file
-
isEditable
public boolean isEditable()
- Overrides:
isEditablein classJEditBuffer- Returns:
- true if this file is editable, false otherwise. A file may become uneditable if it is read only, or if I/O is in progress. This method is thread-safe.
-
isLocked
public boolean isLocked()
- Returns:
- if this buffer is locked for editing
-
setLocked
public void setLocked(boolean locked)
Changes locked state of the buffer.- Parameters:
locked- true to lock, false to unlock
-
toggleLocked
public void toggleLocked(View view)
Toggles locked state of the buffer.- Parameters:
view- We show a message in the view's status bar
-
getIcon
public javax.swing.Icon getIcon()
- Returns:
- this buffer's icon.
- Since:
- jEdit 2.6pre6
-
propertiesChanged
public void propertiesChanged()
Reloads settings from the properties. This should be called after thesyntaxorfoldingbuffer-local properties are changed.- Overrides:
propertiesChangedin classJEditBuffer
-
getDefaultProperty
public java.lang.Object getDefaultProperty(java.lang.String name)
- Overrides:
getDefaultPropertyin classJEditBuffer
-
toggleWordWrap
public void toggleWordWrap(View view)
Toggles word wrap between the three available modes. This is used by the status bar.- Parameters:
view- We show a message in the view's status bar- Since:
- jEdit 4.1pre3
-
toggleAutoIndent
public void toggleAutoIndent(View view)
Toggles automatic indentation on and off.- Parameters:
view- This view's status bar will display the message- Since:
- jEdit 5.0
-
toggleLineSeparator
public void toggleLineSeparator(View view)
Toggles the line separator between the three available settings. This is used by the status bar.- Parameters:
view- We show a message in the view's status bar- Since:
- jEdit 4.1pre3
-
getContextSensitiveProperty
public 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).- Overrides:
getContextSensitivePropertyin classJEditBuffer- Parameters:
offset- The offsetname- The property name- Returns:
- the property value
- Since:
- jEdit 4.0pre3
-
setMode
public void setMode()
Sets this buffer's edit mode by calling the accept() method of each registered edit mode.
-
getFile
@Deprecated public java.io.File getFile()
Deprecated.Do not call this method, usegetPath()instead.- Returns:
- the file
-
getMarkers
public java.util.Vector<Marker> getMarkers()
- Returns:
- a vector of markers.
- Since:
- jEdit 3.2pre1
-
getMarkerStatusPrompt
public java.lang.String getMarkerStatusPrompt(java.lang.String action)
- Parameters:
action- some action- Returns:
- the status prompt for the given marker action. Only
intended to be called from
actions.xml. - Since:
- jEdit 4.2pre2
-
getMarkerNameString
public java.lang.String getMarkerNameString()
- Returns:
- a string of all set markers, used by the status bar (eg, "a b $ % ^").
- Since:
- jEdit 4.2pre2
-
addOrRemoveMarker
public void addOrRemoveMarker(char shortcut, int pos)If a marker is set on the line of the position, it is removed. Otherwise a new marker with the specified shortcut is added.- Parameters:
pos- The position of the markershortcut- The shortcut ('\0' if none)- Since:
- jEdit 3.2pre5
-
addMarker
public void addMarker(char shortcut, int pos)Adds a marker to this buffer.- Parameters:
pos- The position of the markershortcut- The shortcut ('\0' if none)- Since:
- jEdit 3.2pre1
-
getMarkerInRange
public Marker getMarkerInRange(int start, int end)
- Parameters:
start- The start offsetend- The end offset- Returns:
- the first marker within the specified range.
- Since:
- jEdit 4.0pre4
-
getMarkerAtLine
public Marker getMarkerAtLine(int line)
- Parameters:
line- The line number- Returns:
- the first marker at the specified line, or
nullif there is none. - Since:
- jEdit 3.2pre2
-
removeMarker
public void removeMarker(int line)
Removes all markers at the specified line.- Parameters:
line- The line number- Since:
- jEdit 3.2pre2
-
removeAllMarkers
public void removeAllMarkers()
Removes all defined markers.- Since:
- jEdit 2.6pre1
-
getMarker
public Marker getMarker(char shortcut)
- Parameters:
shortcut- The shortcut- Returns:
- the marker with the specified shortcut.
- Since:
- jEdit 3.2pre2
-
getMarkersPath
public static java.lang.String getMarkersPath(VFS vfs, java.lang.String path)
Returns the path for this buffer's markers file- Parameters:
vfs- The appropriate VFSpath- the path of the buffer, it can be different from the field when using save-as- Returns:
- the marker path
- Since:
- jEdit 4.3pre10
-
updateMarkersFile
public 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. Changing markers will not set the buffer dirty any longer.- Parameters:
view- The current view- Returns:
- true if markers were updated
- Since:
- jEdit 4.3pre7
-
markersChanged
public boolean markersChanged()
- Returns:
- true when markers have changed and the markers file needs to be updated
- Since:
- jEdit 4.3pre7
-
setMarkersChanged
public void setMarkersChanged(boolean changed)
Sets/unsets the MARKERS_CHANGED flag- Parameters:
changed- changed- Since:
- jEdit 4.3pre7
-
setWaitSocket
public void setWaitSocket(java.net.Socket waitSocket)
This socket is closed when the buffer is closed.- Parameters:
waitSocket- the socket
-
getNext
public Buffer getNext()
- Returns:
- the next buffer in the list.
-
getPrev
public Buffer getPrev()
- Returns:
- the previous buffer in the list.
-
setPrev
public void setPrev(Buffer prev)
-
setNext
public void setNext(Buffer next)
-
getIndex
public int getIndex()
- Returns:
- the position of this buffer in the buffer list.
-
toString
public java.lang.String toString()
Returns a string representation of this buffer. This simply returns the path name.- Overrides:
toStringin classjava.lang.Object
-
addBufferUndoListener
public void addBufferUndoListener(BufferUndoListener listener)
Adds a buffer undo listener.- Parameters:
listener- The listener- Since:
- jEdit 4.3pre18
-
removeBufferUndoListener
public void removeBufferUndoListener(BufferUndoListener listener)
Removes a buffer undo listener.- Parameters:
listener- The listener- Since:
- jEdit 4.3pre18
-
close
public void close()
-
markTokens
protected TokenMarker.LineContext markTokens(javax.swing.text.Segment seg, TokenMarker.LineContext prevContext, TokenHandler _tokenHandler)
- Overrides:
markTokensin classJEditBuffer
-
fireBeginUndo
protected void fireBeginUndo()
- Overrides:
fireBeginUndoin classJEditBuffer
-
fireEndUndo
protected void fireEndUndo()
- Overrides:
fireEndUndoin classJEditBuffer
-
fireBeginRedo
protected void fireBeginRedo()
- Overrides:
fireBeginRedoin classJEditBuffer
-
fireEndRedo
protected void fireEndRedo()
- Overrides:
fireEndRedoin classJEditBuffer
-
-