org.gjt.sp.jedit
Class Buffer

java.lang.Object
  extended by org.gjt.sp.jedit.buffer.JEditBuffer
      extended by org.gjt.sp.jedit.Buffer

public class Buffer
extends JEditBuffer

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
 
Nested classes/interfaces inherited from class org.gjt.sp.jedit.buffer.JEditBuffer
JEditBuffer.PropValue
 
Field Summary
static java.lang.String BACKED_UP
          Backed up property.
static java.lang.String CARET
          Caret info properties.
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.
 
Fields inherited from class org.gjt.sp.jedit.buffer.JEditBuffer
ENCODING, HIGH_PRIORITY, LINESEP, NORMAL_PRIORITY, seg, textMode, undoMgr
 
Method Summary
 void addBufferChangeListener(BufferChangeListener listener)
          Deprecated. Call JEditBuffer.addBufferListener(BufferListener).
 void addBufferChangeListener(BufferChangeListener listener, int priority)
          Deprecated. Call JEditBuffer.addBufferListener(BufferListener,int).
 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.
 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 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.
 java.lang.String getPath()
          Returns the path name of this buffer.
 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.
 void insertString(int offset, java.lang.String str, javax.swing.text.AttributeSet attr)
          Deprecated. Call insert() instead.
 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.
 Buffer.TokenList markTokens(int lineIndex)
          Deprecated. Use the other form of markTokens() instead
 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 reload(View view)
          Reloads the buffer from disk, asking for confirmation if the buffer has unsaved changes.
 void removeAllMarkers()
          Removes all defined markers.
 void removeBufferChangeListener(BufferChangeListener listener)
          Deprecated. Call JEditBuffer.removeBufferListener(BufferListener).
 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 saveAs(View view, boolean rename)
          Prompts the user for a file to save this buffer to.
 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 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 setWaitSocket(java.net.Socket waitSocket)
          This socket is closed when the buffer is closed.
 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.
 
Methods inherited from class org.gjt.sp.jedit.buffer.JEditBuffer
addBufferListener, addBufferListener, beginCompoundEdit, createPosition, endCompoundEdit, fireBufferLoaded, fireContentInserted, fireContentRemoved, fireFoldHandlerChanged, fireFoldLevelChanged, firePreContentRemoved, fireTransactionComplete, getBooleanProperty, getBufferListeners, getCurrentIndentForLine, getFoldAtLine, getFoldHandler, getFoldLevel, getIdealIndentForLine, getIndentSize, getIntegerProperty, getKeywordMapAtOffset, getLength, getLineCount, getLineEndOffset, getLineLength, getLineOfOffset, getLineStartOffset, getLineText, getLineText, getOffsetOfVirtualColumn, getPatternProperty, getPriorNonEmptyLine, getProperty, getRuleSetAtOffset, getStringProperty, getTabSize, getText, getText, getTokenMarker, getVirtualWidth, indentLine, indentLine, indentLines, indentLines, initIndentRules, insert, insert, insertAtColumn, insertIndented, insideCompoundEdit, invalidateCachedFoldLevels, invalidateFoldLevels, isDirty, isEditable, isElectricKey, isFileReadOnly, isFoldEnd, isFoldStart, isLoading, isPerformingIO, isReadOnly, isTransactionInProgress, isUndoInProgress, loadText, markTokens, parseBufferLocalProperties, readLock, readUnlock, redo, remove, removeBufferListener, removeTrailingWhiteSpace, resetCachedProperties, setBooleanProperty, setDefaultProperty, setFileReadOnly, setFoldHandler, setIntegerProperty, setLoading, setPerformingIO, setProperty, setReadOnly, setStringProperty, setTokenMarker, shiftIndentLeft, shiftIndentRight, undo, unsetProperty, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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

SELECTION

public static final java.lang.String SELECTION
Stores a List of Selection instances.

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 view
reload - If true, user will not be asked to recover autosave file, if any
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 view
Since:
4.0pre1

autosave

public void autosave()
Autosaves this buffer.


saveAs

public boolean saveAs(View view,
                      boolean rename)
Prompts the user for a file to save this buffer to.

Parameters:
view - The view
rename - True if the buffer's path should be changed, false if only a copy should be saved to the specified filename
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 view
path - The path name to save the buffer to, or null to use 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 view
path - The path name to save the buffer to, or null to use the existing path
rename - True if the buffer's path should be changed, false if only a copy should be saved to the specified filename
Since:
jEdit 2.6pre5

checkFileStatus

public int checkFileStatus(View view)
Check if the buffer has changed on disk.

Returns:
One of NOT_CHANGED, CHANGED, or 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

getVFS

public VFS getVFS()
Returns the virtual filesystem responsible for loading and saving this buffer. This method is thread-safe.


getAutosaveFile

public java.io.File getAutosaveFile()
Returns the autosave file for this buffer. This may be null if the file is non-local.


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.


getSymlinkPath

public java.lang.String getSymlinkPath()
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.


setDirty

public void setDirty(boolean d)
Sets the 'dirty' (changed since last save) flag of this buffer.

Overrides:
setDirty in class JEditBuffer

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)

getIcon

public javax.swing.Icon getIcon()
Returns this buffer's icon.

Since:
jEdit 2.6pre6

addBufferChangeListener

public void addBufferChangeListener(BufferChangeListener listener,
                                    int priority)
Deprecated. Call JEditBuffer.addBufferListener(BufferListener,int).


addBufferChangeListener

public void addBufferChangeListener(BufferChangeListener listener)
Deprecated. Call JEditBuffer.addBufferListener(BufferListener).


removeBufferChangeListener

public void removeBufferChangeListener(BufferChangeListener listener)
Deprecated. Call JEditBuffer.removeBufferListener(BufferListener).


propertiesChanged

public void propertiesChanged()
Reloads settings from the properties. This should be called after the syntax or folding buffer-local properties are changed.


getDefaultProperty

public java.lang.Object getDefaultProperty(java.lang.String name)
Overrides:
getDefaultProperty in class JEditBuffer

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

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:
getContextSensitiveProperty in class JEditBuffer
Parameters:
offset - The offset
name - The property name
Since:
jEdit 4.0pre3

getMode

public Mode getMode()
Returns this buffer's edit mode. This method is thread-safe.


setMode

public void setMode(java.lang.String mode)
Sets this buffer's edit mode. Note that calling this before a buffer is loaded will have no effect; in that case, set the "mode" property to the name of the mode. A bit inelegant, I know...

Parameters:
mode - The mode name
Since:
jEdit 4.2pre1

setMode

public void setMode(Mode mode)
Sets this buffer's edit mode. Note that calling this before a buffer is loaded will have no effect; in that case, set the "mode" property to the name of the mode. A bit inelegant, I know...

Parameters:
mode - The mode

setMode

public void setMode()
Sets this buffer's edit mode by calling the accept() method of each registered edit mode.


putProperty

public void putProperty(java.lang.Object name,
                        java.lang.Object value)
Deprecated. Call setProperty() instead.


putBooleanProperty

public void putBooleanProperty(java.lang.String name,
                               boolean value)
Deprecated. Call setBooleanProperty() instead


markTokens

public Buffer.TokenList markTokens(int lineIndex)
Deprecated. Use the other form of markTokens() instead


insertString

public void insertString(int offset,
                         java.lang.String str,
                         javax.swing.text.AttributeSet attr)
Deprecated. Call insert() instead.


getFile

public java.io.File getFile()
Deprecated. Do not call this method, use getPath() instead.


getMarkers

public java.util.Vector getMarkers()
Returns a vector of markers.

Since:
jEdit 3.2pre1

getMarkerStatusPrompt

public java.lang.String getMarkerStatusPrompt(java.lang.String 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 marker
shortcut - 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 marker
shortcut - The shortcut ('\0' if none)
Since:
jEdit 3.2pre1

getMarkerInRange

public Marker getMarkerInRange(int start,
                               int end)
Returns the first marker within the specified range.

Parameters:
start - The start offset
end - The end offset
Since:
jEdit 4.0pre4

getMarkerAtLine

public Marker getMarkerAtLine(int line)
Returns the first marker at the specified line, or null if there is none.

Parameters:
line - The line number
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)
Returns the marker with the specified shortcut.

Parameters:
shortcut - The shortcut
Since:
jEdit 3.2pre2

setWaitSocket

public void setWaitSocket(java.net.Socket waitSocket)
This socket is closed when the buffer is closed.


getNext

public Buffer getNext()
Returns the next buffer in the list.


getPrev

public Buffer getPrev()
Returns the previous buffer in the list.


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:
toString in class java.lang.Object