Sandy - a simple text editor
sandy - a simple text editor
Sandy is a X11 text editor with an easy-to-read, hackable C source. It uses GTK+ and GtkSourceView for convenience and is akin to surf, only it is a text editor, not a web browser. Sandy tries to maximize screen estate, minimize the SLOC used and not get in your way too much. It can somehow be controlled via XProperties and all preferences and keybindings are to be chosen at compile time. Two example configs are provided with the source.
Features
- Basic editing, saving, etc.
- One document per instance
- Embeddable (e.g. can use http://tools.suckless.org/tabbed for tabs)
- Regex search, go to line functionalities
- Pipe selection through arbitrary command
- Pipe selection through predefined command(s)
- Syntax highlighting
- Line numbers, current line highlightnig
- Simple autoindenting
- Multi-level undo
- Configurable at compile-time
Dependencies
- GtkSourceView2
- Gtk+2
- (probably) xorg-utils to get xprop to set XProperties
- one method to grab user input: either zenity or dmenu in the pre-defined config files
Screenshot
http://sandyeditor.sf.net/sandy_editor.jpeg
Homepage
http://sandyeditor.sf.net/
Download
http://sourceforge.net/projects/sandyed … z/download
AUR
http://aur.archlinux.org/packages.php?ID=36084
Comments, bug reports and patches welcome.
Last edited by rafunchi (2010-04-13 23:24:26)
Procyon wrote:
It would be nice to be able to do something like this:
1 abc
2 dec
3 abd
4 edc
5 {CURSOR}ad
^R, sed command: 1,3s/^/%%%/
1 %%%abc
2 %%%dec
3 %%%abd
4 edc
5 {CURSOR}ad
So you can edit and continue where you left off.
The problem with implementing this behavior is 'sed' is an external command here. The full text is filtered through sed and put back in the buffer, not just lines 1 to 3. You can't just preserve the insert position as the text coming from the pipe might be completely different from your original. Same for searching the current line.
You *could* remember your line+char position and move the cursor back there, but this would be highly unreliable and move the cursor to a third position in the buffer if your 's' command changes the number of lines (e.g. try s/:/\n/g in a password file)
Also, a couple of tests with vim prove that it does not behave consistently in this regard, despite :s being an internal command there.
if you really want to add '%%%' at the beginning of the line quite often, I suggest you define a binding or action for:
t_editable, t_pipelines, { .v = (char *)"sed \'s/^/%%%/\'" }
Then select the lines you want to target lousily (you don't need to select full lines) and launche the binding/action. It does move the cursor, but seems fairly quick.
Procyon wrote:Maybe you can check for "/^s/" in the command to make it work on this current line, just like vim's :s///
I made a wee change in the hg tip code. Now sandy "listens" to three properties regarding pipes:
- _SANDY_PIPE: Pipes the selected text, or nothing by default as per f_pipe. This is used by the ^I binding in the default config.
- _SANDY_PIPEALL: Pipes the selected text, or the full file if nothing is selected as per f_pipeall. This is used by the ^P binding in the default config.
- _SANDY_PIPELINES: Pipes the selected text, extending the selection to full lines and matching the current line if there is no selection as per f_pipelines. This is used by the ^R binding in the default config. This means now sed is applied to full lines if there is a selection and to the current line if there is not.
Thanks for your feedback. I hope this helps.
Similar Messages
-
Efficient data structure to implement simple text editor?
I was given this problem in an interview:
What data structure would you use to implement a simple text editor that does these 4 functions:
a) goto(line number)
b) insert(char input,location)
c) delete(location)
d) printAll() //print entire file
Given that i'm such a newb, i was stumped. I came up with making a 2d array that would allow for o(1) time for goto, but o(n) for everything else (shifting everything in the array). there were other downfalls too dealing with space issues and such, but he wanted me to optimize this data structure. I then came up with a linked list of arrays, but that had similar problems.
But thinking about it further is driving me a little crazy so I'm wondering if you guys have any suggestions on how to answer this question...
one thing that came to mind after is to implement the data structure as a binary tree, where each node contains
class Node
char theChar
int position; // ie 0 = first character in the file, and 81 could be the first character in the 2nd line
node left,right,parent;
}so how it works is the cursor would know where the location was so i would know where to delete and insert within the tree.
insert {
//search for location to insert after (log n)
//create new character node and append to current node
//increment position for all subsequent children
delete(x) {
search for x position
if found, remove node and decrement position value for all children
goto(line #) {
return line # * 80 (or whatever max length for a single line)
}the major problem i see here is balancing the tree after every insert/delete
Thanks in advance.One of many great things emacs has given us is the gap buffer:
http://en.wikipedia.org/wiki/Gap_buffer
To see a Java implementation of this you can look in the Java SDK source. The document model (I forget exactly what its called), used in Swing uses a gap buffer. -
How can I add highlighting to my simple text editor?
Hi ...I wrote a simple text editor ..but I want to add Sysntax highlihting to my editor ...ilke I will enter some words in sourse code (new..import.. ext ) and when I write in text those words I want to see whit a different collor ..how can I do this? here is source codes for my text editor..and I want your help
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.regex.*;
public class JText extends JFrame{
private JTextArea textarea ;
private JFileChooser fileChooser = new JFileChooser();
private Action open =new OpenAction() ;
private Action save = new SaveAction();
private Action exit = new ExitAction();
public static void main(String args[])
JText pencere= new JText();
pencere.setBackground(Color.lightGray);
pencere.setSize(400,300);
pencere.setVisible(true);
//Text Area
public JText(){
textarea = new JTextArea(15,90) ;
JScrollPane scroll = new JScrollPane(textarea);
JPanel content = new JPanel();
content.setLayout(new BorderLayout());
content.add(scroll, BorderLayout.CENTER);
//Menu Bar
JMenuBar menu=new JMenuBar();
JMenu file=menu.add(new JMenu("FILE"));
file.setMnemonic('F');
file.add(open);
file.add(save);
file.addSeparator();
file.add(exit);
setContentPane(content);
setJMenuBar(menu);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Project");
pack();
setLocationRelativeTo(null);
setVisible(true);
class OpenAction extends AbstractAction {
//============================================= constructor
public OpenAction() {
super("Open...");
putValue(MNEMONIC_KEY, new Integer('O'));
//========================================= actionPerformed
public void actionPerformed(ActionEvent e) {
int retval = fileChooser.showOpenDialog(JText.this);
if (retval == JFileChooser.APPROVE_OPTION) {
File f = fileChooser.getSelectedFile();
try {
FileReader reader = new FileReader(f);
textarea.read(reader, ""); // Use TextComponent read
} catch (IOException ioex) {
System.out.println(e);
System.exit(1);
class SaveAction extends AbstractAction {
//============================================= constructor
SaveAction() {
super("Save...");
putValue(MNEMONIC_KEY, new Integer('S'));
//========================================= actionPerformed
public void actionPerformed(ActionEvent e) {
int retval = fileChooser.showSaveDialog(JText.this);
if (retval == JFileChooser.APPROVE_OPTION) {
File f = fileChooser.getSelectedFile();
try {
FileWriter writer = new FileWriter(f);
textarea.write(writer); // Use TextComponent write
} catch (IOException ioex) {
JOptionPane.showMessageDialog(JText.this, ioex);
System.exit(1);
class ExitAction extends AbstractAction {
//============================================= constructor
public ExitAction() {
super("Exit");
putValue(MNEMONIC_KEY, new Integer('X'));
//========================================= actionPerformed
public void actionPerformed(ActionEvent e) {
System.exit(0);
}i looked it ...it is the one which i want to do ..But i want to use my window which i gave above ..But i cant mix them ..:( this codes for highlighting.... is any body can add this codes and my codes which i gave above connect together? pleaseeeee... :))
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class SyntaxTest extends DefaultStyledDocument
Element rootElement;
String wordSeparators = ",:;.()[]{}+-/*%=!&|~^@? ";
Vector keywords = new Vector();;
SimpleAttributeSet keyword;
public SyntaxTest()
rootElement= this.getDefaultRootElement();
keyword = new SimpleAttributeSet();
StyleConstants.setForeground(keyword, Color.blue);
keywords.add( "abstract" );
keywords.add( "boolean" );
keywords.add( "break" );
keywords.add( "byte" );
keywords.add( "case" );
keywords.add( "catch" );
keywords.add( "char" );
keywords.add( "class" );
keywords.add( "continue" );
keywords.add( "default" );
keywords.add( "do" );
keywords.add( "double" );
keywords.add( "else" );
keywords.add( "extends" );
keywords.add( "false" );
keywords.add( "final" );
keywords.add( "finally" );
keywords.add( "float" );
keywords.add( "for" );
keywords.add( "if" );
keywords.add( "implements" );
keywords.add( "import" );
keywords.add( "instanceof" );
keywords.add( "int" );
keywords.add( "interface" );
keywords.add( "long" );
keywords.add( "native" );
keywords.add( "new" );
keywords.add( "null" );
keywords.add( "package" );
keywords.add( "private" );
keywords.add( "protected" );
keywords.add( "public" );
keywords.add( "return" );
keywords.add( "short" );
keywords.add( "static" );
keywords.add( "super" );
keywords.add( "switch" );
keywords.add( "synchronized" );
keywords.add( "this" );
keywords.add( "throw" );
keywords.add( "throws" );
keywords.add( "true" );
keywords.add( "try" );
keywords.add( "void" );
keywords.add( "volatile" );
keywords.add( "while" );
public void insertString(int offset, String str, AttributeSet a) throws BadLocationException
super.insertString(offset, str, a);
int startOfLine = rootElement.getElement(rootElement.getElementIndex(offset)).getStartOffset();
int endOfLine = rootElement.getElement(rootElement.getElementIndex(offset+str.length())).getEndOffset() -1;
//highlight the changed line
highlightKeyword(this.getText(0,this.getLength()), startOfLine, endOfLine);
public void remove(int offset, int length) throws BadLocationException
super.remove(offset, length);
int startOfLine = rootElement.getElement(rootElement.getElementIndex(offset)).getStartOffset();
int endOfLine = rootElement.getElement(rootElement.getElementIndex(offset+length)).getEndOffset() -1;
//highlight the changed line
highlightKeyword(this.getText(0,this.getLength()), startOfLine, endOfLine);
public void highlightKeyword(String content,int startOffset, int endOffset)
char character;
int tokenEnd;
while (startOffset < endOffset)
tokenEnd = startOffset;
//find next wordSeparator
while(tokenEnd < endOffset)
character = content.charAt(tokenEnd);
if(wordSeparators.indexOf(character) > -1)
break;
else
tokenEnd++;
//check for keyword
String token = content.substring(startOffset,tokenEnd).trim();
if(keywords.contains(token))
this.setCharacterAttributes(startOffset, token.length(), keyword, true);
startOffset = tokenEnd+1;
public static void main(String[] args)
JFrame f = new JFrame();
JTextPane pane = new JTextPane(new SyntaxTest());
JScrollPane scrollPane = new JScrollPane(pane);
f.setContentPane(scrollPane);
f.setSize(600,400);
f.setVisible(true);
} -
Is There A Simple Text Editor/Composter & Line Art Plug-In Available
Yes, I know it has been addressed in other posts in the past but I wanted to know if any new tools are available since the update to 3.XX, outside of open a picture in a "Book" project and adding text in a border or downloading BorderFX, neither of which provide a direct result.
For such an advanced piece of software, I find it infurirating that the only way to create simple focus cicles, highlight boxes, insert arrows, lines or create and insert text directly on an image after cleaning it up is to
Import > Save > Export > Reopen In the OSX Built-in Image Preview > Perform Functions Using Its Tools > Re-Save Version.
Even the most rudimentary photo altering programs like MS Paint and have this basic toolset in the standard the package. How or rather why would Apple klutz this up?I can respect that thousands of users have accepted the current status-quo of these applications,
What is there to accept? it would be different, if Aperture claimed to be a program for graphics compositing, but it is not. Aperture is a tool for a different purpose.
Here is how Aperture is advertized in the store:
Aperture gives you all the tools you need to uncover the hidden potential in your photos. It brings you even more advanced ways to organize, browse, and perfect images.
So you can make every shot your best shot.
And that does Aperture really well. If you want a painting program, why buy Aperture? -
Simple text Editor App.. Saving Plain Text
Hi All,
I am trying to write my first text application in cocoa... I have got a working app from an Apple tutorial, however when saving, it uses the following:
Code:
- (NSData *)dataRepresentationOfType:(NSString *)aType
NSData *data;
[self setString:[textView textStorage]];
data = [NSArchiver archivedDataWithRootObject:[self string]];
return data;
Which saves the content as not plain text. Is there anyway I can change the above to save as plain text ?
Any help / direction would be great! Thanks,Perhaps something like this will work for you:
NSString *s = [textView string];
NSData *data = [NSData dataWithBytes: [s UTF8String] length: [s length]]; -
Can someone advise me on how I can click anywhere on the
canvas/stage to create a text field where you can input text.
I have seen similar functionality at
www.imagination3.com where
you can see the function if you go to TOOLS > TYPE.
Any assistance will be appreciated.I'm not sure I'm on the right forum, sorry
You are not in the right forum !
This is Compressor 2 forum.
You probably have to post your question in OSX forum:
http://discussions.apple.com/category.jspa?categoryID=160
Good luck!
Alberto -
Is a text editor really better than Dreamweaver?
Hi Everyone,
I've been looking through several different web design forums
and I'm now stuck with a question. Why do some people swear by
using only a text editor to put their website together and totally
discount programs such as Dreamweaver? I find this quite strange
because a website amongst other things is a highly visual
experience usually not showing a single line of code to the end
user. I get the impression that some people feel that Dreamweaver
is beneath them as they are "highly skilled coders" and only
amateurs use WYSIWYGs! Is it just me or am I correct in thinking
there is an element of snobbery here? To me it seems that
Dreamweaver has advantages in abundance and for the so called
hardcore coders there's even a code view which is much more
powerful than a simple text editor. One final thing, I see that
people complain about so called bad code that Dreamweaver writes.
Is it true that Dreamweaver writes bad code and if so what's bad
about it?
Many thanks, I'll be fascinated to read your
responses.Let's see entire sites, good-sized professional ones. :-)
Patty Ayers | www.WebDevBiz.com
Free Articles on the Business of Web Development
Web Design Contract, Estimate Request Form, Estimate
Worksheet
"Murray *ACE*" <[email protected]> wrote
in message
news:[email protected]...
> Good idea, Patty. Let's see some of the "wouldn't touch
DW with a 10-foot
> pole" pages that have been created....
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
>
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
>
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
> ==================
>
>
> "P@tty Ayers ~ACE"
<[email protected]> wrote in message
> news:[email protected]...
>> This question is asked a lot. The answers are:
>>
>> -- No, a text editor isn't just as good. There are
lots of extremely
>> useful things DW does that a text editor can't do.
>>
>> -- No, the recent versions of Dreamweaver actually
write very good code
>> in general.
>>
>> -- In response to "only amateurs use [Dreamweaver
instead of a text
>> editor]" - please show me just 1 full-time
professional web developer
>> responsible for creating and maintaining sites who
uses only a text
>> editor. Just 1. You won't be able to, because there
isn't one. Not one
>> with a job, anyway. :-)
>>
>> Cheers,
>>
>> --
>> Patty Ayers | www.WebDevBiz.com
>> Free Articles on the Business of Web Development
>> Web Design Contract, Estimate Request Form, Estimate
Worksheet
>> --
>>
>>
>>
>> "In at the deep end"
<[email protected]> wrote in message
>> news:[email protected]...
>>> Hi Everyone,
>>>
>>> I've been looking through several different web
design forums and I'm
>>> now
>>> stuck with a question. Why do some people swear
by using only a text
>>> editor to
>>> put their website together and totally discount
programs such as
>>> Dreamweaver? I
>>> find this quite strange because a website
amongst other things is a
>>> highly
>>> visual experience usually not showing a single
line of code to the end
>>> user. I
>>> get the impression that some people feel that
Dreamweaver is beneath
>>> them as
>>> they are "highly skilled coders" and only
amateurs use WYSIWYGs! Is it
>>> just me
>>> or am I correct in thinking there is an element
of snobbery here? To me
>>> it
>>> seems that Dreamweaver has advantages in
abundance and for the so called
>>> hardcore coders there's even a code view which
is much more powerful
>>> than a
>>> simple text editor. One final thing, I see that
people complain about so
>>> called
>>> bad code that Dreamweaver writes. Is it true
that Dreamweaver writes bad
>>> code
>>> and if so what's bad about it?
>>>
>>> Many thanks, I'll be fascinated to read your
responses.
>>>
>>
> -
I have been looking for a good macintosh Java text editor for my newphew. His high school is primary macintosh (Mac OS X) workstation based, therefore in order to code/learn Java, he understands that he can use a simple text editor.
Is there a good text editor for the macintosh? Maybe a comparison is BBEdit for web site development, something with that power.
Or is there a better simple editor in the terminal he can use?
Thank you for reading this post.You can use TextEdit in plain text mode, or you can go to http://developer.apple.com/ and get Apple's free Project Builder IDE of OS X10.2, which works OK most the time as a text editor with syntax highlighting, but I've found tends to fall over when you try to debug; I've just ordered OS X 10.3 which comes with XCode, which looks prettier, and may even work.
For the one or two class examples I post here, I use project builder as a text editor, and compile from the terminal. For larger projects, I use project builder but have to be disciplined about saving regularly.
I've also used J (http://sourceforge.net/projects/armedbear-j/), though mainly under linux on a slow laptop, which is quite fast and lightweight, and being Java portable. I will go try it on the Mac forthwith.
Pete -
Lightweight text editor?
I need to provide a basic text editor in my swing commercial app.
Rather than reinventing the wheel are there any freely available fine tuned lightweight editors available in a jar that I can use for this purpose?
There is http://syntax.jedit.org/ which uses the MIT/X11 licence but though it is extremely lightweight the code has not been updated in 7 years and is not wrapped in a package...also the functionality is supports is still way overkill for my needs (for example it supports syntax highlighting for 10+ code file types). I guess what i was hoping for was a well used java class that encapsulated a simple text editor.....
Thanks,
Tom.
Edited by: tyk on Nov 26, 2007 7:31 AMTrue. I found myself having to add cut/copy/paste which is not such a big deal and just wondered if there was any simple class out there that people reuse...but i guess everyone just writes their own :-(
-
Text Editor (trying to write my own)
I am trying to write a simple text editor with a 'Find' option.
Is JEditorPane the right class to use?
How would I search for a certain string and then scroll to make it appear at the top of the window?
Thanks,
ElenaHi Elena,
JEditorPane is 'just' showing contents which are actually coming from a Document. So class Document and its descendants would be the one to be searched.
Keeping performance and optimization out of sight, using class ElementIterator to iterate through all Elements of a Document could be a way to start with. Each Element can represent content, which then would have to be tested on the text to be found.
Once an occurence of the searched text portion is found, the Element having the respective content has properties (getStartOffset and getEndOffset) to find out the position within the Document to scroll to.
Pls see the API docs for the mentioned classes too.
Hope this helps.
Ulrich -
Help - need text editor component
Hello,
I need a simple text editor component to add to my application.
I need to load it from a database file line by line.
It must be able to handle page breaks (new page) when the user types more than will fit on a page.
I have not been able to find anything to do this in java, I found a .net TextControl, but I want to stay in java if possible.
Are there any code samples or anything available to do this?
If it does not handle page breaks, it is useless to me because I need to write the text back to the database and must be able to handle multi-page.
I thought about fileing a jtextarea one page at a time by loading the text in an array. I still have the problem of if the user types more than will fit on a page.
Thanks for the help.
FrankThat might help you.
http://forum.java.sun.com/thread.jsp?forum=57&thread=42
964
regards,
StasWow! That's a gem - erm - (havent tested /run it yet but) ...thank you -
Is there a Simple free Text Editor for Belle?
Symbian has been around for a very long time but I'm still struggling to find a
simple free text editor where I can create a *.txt file and write down information in it or perhaps I don't know about it, so I was wondering is anyone familiar in any free text editor compatible with Belle?
Thanking you in advance.
Bobak.I use Notes. You know, standard notes. And easiest way to get this "file" out from the phone is to send it by e-mail.
-
Looking for Simple PDF Text Editor
I have a very old laptop, and wanted a "simple PDF Text Editor".
Basically, just a really express version where I can open a PDF, edit the existing text on the document and then resave the PDF.
What's the simplest version without installing the Suites, or the full program?
Is there just a simple version available?Adobe sells Acrobat Standard and Pro, that's it. Editing text in a PDF is not a trivial task, they're not intended to be editable documents.
-
Hi,
I have been using text editor control.
In this when we click load file button...an open prompt window appears..
there we will be finding Files of type... dropdown..containing values like text(.txt) file and All file types..
Is there any way to restrict this dropdown to single value..i mean to .txt file..should only be viewed omitting
All files option in dropdown..
i am using CL_GUI_TEXTEDIT..control...
Is there any option to do it...
Please Help me out.
Thanks & Regards,
Sandy.Hi Sandy,
I don't think there is any method for this. As the dialog box opened is depending on your OS.
But, you can cross check the uploaded file for " .txt " using CP (contains pattern) function of string.
DATA: xl type string.
xl = '*.txt'.
IF not P_FILE CP xl. "P_FILE is name of file you will get.
"Error"
ENDIF.
Sachin -
We have portal release 2 running on HP-UX.
In release 2 there is a new text editor for publishing text. Its used for simple text and text item types.
How is this feature implemented? Is the source code available?
Feedback appreciated.Hi,
It is called Rich Text editing. A search on google with the keywords rich text edit
will give you links to quite a few sites, where the source is available. It uses
a combination of DHTML and JavaScript.
We have portal release 2 running on HP-UX.
In release 2 there is a new text editor for publishing text. Its used for simple text and text item types.
How is this feature implemented? Is the source code available?
Feedback appreciated.
Maybe you are looking for
-
Service order number range creation
Hi, Could anyone please tell me how can we create service order number range if we have done a new service order type creation, and what should we do: should we create the number range in development and then transport it to the production or we shou
-
Query Group in Query Category different with Authorization's group number
Hi All, In Authorization screen, it allowed to authorize up to 20 query group Whereas in Query Category window, it has only max 15 query group. Anyone has idea on why is the difference? Thanks in advance, MH
-
Auto Asset code create in PR/PO
Dear Gurus, Can you guide me How can i activate AUTO ASSET create during account assignment catagory in PR/PO is "A" that is asset. Thanks, MM
-
I have a problem in creating a web service
Hi, I have a problem in creating a webservice usind NWDS.i have done a right click on session bean and selected webservice but no wizard is coming.But it is working fine for other session beans in other projects.will u pls help me out.
-
Hi, Can I copy the whole source XML into one element using the graphical mapping ?? rgds, Amair