Skip to content

Instantly share code, notes, and snippets.

@thata
Created May 27, 2012 16:09
Show Gist options
  • Save thata/2814918 to your computer and use it in GitHub Desktop.
Save thata/2814918 to your computer and use it in GitHub Desktop.
Arduino IDEにEmacs風のキーバインドを追加するパッチ
diff --git a/app/src/processing/app/syntax/InputHandler.java b/app/src/processing/app/syntax/InputHandler.java
index 9a11d38..764cc06 100644
--- a/app/src/processing/app/syntax/InputHandler.java
+++ b/app/src/processing/app/syntax/InputHandler.java
@@ -73,6 +73,9 @@ public abstract class InputHandler extends KeyAdapter
public static final ActionListener CLIPBOARD_CUT = new clipboard_cut(); // [fry]
public static final ActionListener CLIPBOARD_COPY = new clipboard_copy();
public static final ActionListener CLIPBOARD_PASTE = new clipboard_paste();
+ public static final ActionListener BEGIN_LINE = new begin_line();
+ public static final ActionListener END_LINE = new end_line();
+ public static final ActionListener DELETE_LINE = new delete_line();
// Default action
public static final ActionListener INSERT_CHAR = new insert_char();
@@ -119,6 +122,9 @@ public abstract class InputHandler extends KeyAdapter
actions.put("clipboard-cut",CLIPBOARD_CUT);
actions.put("clipboard-copy",CLIPBOARD_COPY);
actions.put("clipboard-paste",CLIPBOARD_PASTE);
+ actions.put("begin-line",BEGIN_LINE);
+ actions.put("end-line",END_LINE);
+ actions.put("delete-line",DELETE_LINE);
}
/**
@@ -1133,4 +1139,65 @@ public abstract class InputHandler extends KeyAdapter
}
}
}
+
+ public static class begin_line implements ActionListener
+ {
+
+ public void actionPerformed(ActionEvent evt)
+ {
+
+ JEditTextArea textArea = getTextArea(evt);
+ int caret = textArea.getCaretPosition();
+ int line = textArea.getCaretLine();
+
+ if(line == 0)
+ {
+ textArea.setCaretPosition(0);
+ return;
+ }
+
+ textArea.setCaretPosition(textArea.getLineStartOffset(line));
+
+
+ }
+ }
+
+ public static class end_line implements ActionListener
+ {
+ public void actionPerformed(ActionEvent evt)
+ {
+ JEditTextArea textArea = getTextArea(evt);
+ int caret = textArea.getCaretPosition();
+ int line = textArea.getCaretLine();
+
+ textArea.setCaretPosition(textArea.getLineStopOffset(line)-1);
+ }
+ }
+
+ public static class delete_line implements ActionListener
+ {
+ public void actionPerformed(ActionEvent evt)
+ {
+ JEditTextArea textArea = getTextArea(evt);
+ int start = textArea.getSelectionStart();
+ int line = textArea.getCaretLine();
+ int end = textArea.getLineStopOffset(line)-1;
+ int document_end = textArea.getDocumentLength();
+ try {
+ int length;
+ if (start == document_end) {
+ length = 0;
+ } else if (start == end) {
+ length = 1;
+ } else {
+ length = end - start;
+ }
+ if (length > 0) {
+ textArea.getDocument().remove(start, length);
+ }
+ } catch(BadLocationException bl) {
+ bl.printStackTrace();
+ }
+ }
+ }
}
diff --git a/app/src/processing/app/syntax/PdeTextAreaDefaults.java b/app/src/processing/app/syntax/PdeTextAreaDefaults.java
index 382c69a..656da05 100644
--- a/app/src/processing/app/syntax/PdeTextAreaDefaults.java
+++ b/app/src/processing/app/syntax/PdeTextAreaDefaults.java
@@ -111,6 +111,16 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
inputHandler.addKeyBinding("S+PAGE_UP", InputHandler.SELECT_PREV_PAGE);
inputHandler.addKeyBinding("S+PAGE_DOWN", InputHandler.SELECT_NEXT_PAGE);
+ // Some basic Emacs-keybindings
+ inputHandler.addKeyBinding("C+b", InputHandler.PREV_CHAR);
+ inputHandler.addKeyBinding("C+f", InputHandler.NEXT_CHAR);
+ inputHandler.addKeyBinding("C+p", InputHandler.PREV_LINE);
+ inputHandler.addKeyBinding("C+n", InputHandler.NEXT_LINE);
+ inputHandler.addKeyBinding("C+a", InputHandler.BEGIN_LINE);
+ inputHandler.addKeyBinding("C+e", InputHandler.END_LINE);
+ inputHandler.addKeyBinding("C+d", InputHandler.DELETE);
+ inputHandler.addKeyBinding("C+k", InputHandler.DELETE_LINE);
+
inputHandler.addKeyBinding("LEFT", InputHandler.PREV_CHAR);
inputHandler.addKeyBinding("S+LEFT", InputHandler.SELECT_PREV_CHAR);
inputHandler.addKeyBinding(mod + "+LEFT", InputHandler.PREV_WORD);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment