]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added shortcuts for adding and jumping to bookmarks
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 26 May 2017 13:00:42 +0000 (09:00 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 26 May 2017 13:00:42 +0000 (09:00 -0400)
TODO.md
docs/xedit.1
docs/xedit.1.md
inc/win.h
inc/x11.h
lib/win.c
xedit.c

diff --git a/TODO.md b/TODO.md
index ded4f4ff789df7f49ae0c7dfdef9302e05d2e144..94990bb15572ecb97d2eba17848d81b42813f3f2 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -8,8 +8,6 @@ Up Next:
     var infoId = 'readerinfo'+reader.id;
 * rename to tide
 
-* Ctrl+Shift+N to set a mark, Ctrl+N to jump to a mark
-* Make Fn keys execute nth command in the tags buffers
 * Add a way to CD using a builtin
 * Ctrl+PageUp/Dn to move cursor by screenfuls
 * Ctrl+\ Shortcut to warp cursor to middle of current screen.
@@ -22,6 +20,7 @@ Up Next:
 
 The Future:
 
+* Make Fn keys execute nth command in the tags buffers
 * use transaction ids to only mark buffer dirty when it really is
 * refactor selection handling to buf.c to prepare for multiple selections.
 * 100% coverage with unit and unit-integration tests
index 1e47a966bac368e96e56f64031d5dfc548b3c4d9..32ae155d7e0f08892ef5c915c04195f7d1b1ee91 100644 (file)
@@ -220,6 +220,17 @@ Scroll the active region up by one screenful of text\. The cursor is not affecte
 \fBPageDn\fR
 Scroll the active region down by one screenful of text\. The cursor is not affected by this operation\.
 .
+.SS "Bookmark Shortcuts"
+\fBxedit\fR supports marking locations in a document to quickly jump to later\. This eases navigation between multiple locations in a large document\.
+.
+.TP
+\fBCtrl+[0\-9]\fR
+Jump to a bookmarked location\.
+.
+.TP
+\fBCtrl+Alt+[0\-9]\fR
+Save the cursor location as a bookmark
+.
 .SS "Search Shortcuts"
 The shortcuts below allow the user to search for selected text or by context\. The direction of the search defaults to the forward direction with regard to the position in the file\. Each search follows the direction of the previous search unless the \fBShift\fR modifier is applied\. The \fBShift\fR modifier causes the current search operation to be applied in the opposite direction of the previous\.
 .
@@ -270,6 +281,10 @@ Launch xtagpick(1) to select a tag from a ctags(1) generated index file\. \fBxed
 Lookup the selected symbol or symbol under the cursor in a ctags(1) generated index file\. Jump to the location of the definition if it exist in the current file\. Otherwise, a new instance of \fBxedit\fR will be launched with the target file and the cursor set to the line containing the definition\.
 .
 .TP
+\fBCtrl+Shift+g\fR
+Jump to the previous cursor location\.
+.
+.TP
 \fBCtrl+n\fR
 Open a new instance of \fBxedit\fR with no filename\.
 .
index 71f4767eba9f30b4a5416f3d6ee93c70bd34b71c..65c2007b11ddbb2f8f714e16c5d58d2e28c22cbd 100644 (file)
@@ -250,6 +250,17 @@ position.
     Scroll the active region down by one screenful of text. The cursor is not
     affected by this  operation.
 
+### Bookmark Shortcuts
+
+`xedit` supports marking locations in a document to quickly jump to later. This
+eases navigation between multiple locations in a large document.
+
+* `Ctrl+[0-9]`:
+    Jump to a bookmarked location.
+
+* `Ctrl+Alt+[0-9]`:
+    Save the cursor location as a bookmark
+
 ### Search Shortcuts
 
 The shortcuts below allow the user to search for selected text or by context.
index 77b464ac028376b42490c2c596454dc8447cdc83..911746d206d88cfb9ba0fe9e17fec7dd21af2028 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -45,6 +45,7 @@ void win_dialog(char* name, void (*errfn)(char*));
 void win_loop(void);
 void win_settext(WinRegion id, char* text);
 void win_setruler(size_t ruler);
+Rune win_getkey(void);
 void win_setkeys(KeyBinding* bindings);
 void win_setmouse(MouseConfig* mconfig);
 void win_warpptr(WinRegion id);
index 8fd3bcd0c65d66b3527f0d3632bb0ea004bddc97..6137c6a1445c498790bcbb41e6836b5cb7c0ce2f 100644 (file)
--- a/inc/x11.h
+++ b/inc/x11.h
@@ -103,6 +103,7 @@ enum {
     ModNumLock    = (1 << 4),
     ModScrollLock = (1 << 5),
     ModWindows    = (1 << 6),
+    ModOneOrMore  = (ModCtrl|ModAlt),
     ModAny        = -1
 };
 
index 84666837fe46f89abd7e98ed1f10ba9dcf1a4285..8b9fe69a648a4c1d92ad33b2f32f01a5bb609fe6 100644 (file)
--- a/lib/win.c
+++ b/lib/win.c
@@ -29,7 +29,8 @@ static XConfig Config = {
 };
 static WinRegion Focused = EDIT;
 static Region Regions[NREGIONS] = {0};
-KeyBinding* Keys = NULL;
+static Rune LastKey;
+static KeyBinding* Keys = NULL;
 
 static void win_init(void (*errfn)(char*)) {
     for (int i = 0; i < SCROLL; i++)
@@ -92,6 +93,10 @@ void win_setruler(size_t ruler) {
     Ruler = ruler;
 }
 
+Rune win_getkey(void) {
+    return LastKey;
+}
+
 void win_setkeys(KeyBinding* bindings) {
     Keys = bindings;
 }
@@ -229,14 +234,19 @@ static void onredraw(int width, int height) {
 }
 
 static void oninput(int mods, Rune key) {
+    LastKey = key;
     /* mask of modifiers we don't care about */
-    mods = mods & (ModCtrl|ModAlt|ModShift);
+    mods = mods & (ModCtrl|ModShift|ModAlt);
     /* handle the proper line endings */
     if (key == '\r') key = '\n';
     /* search for a key binding entry */
     uint32_t mkey = tolower(key);
     for (KeyBinding* bind = Keys; bind && bind->key; bind++) {
-        if ((mkey == bind->key) && (bind->mods == ModAny || bind->mods == mods)) {
+        bool match   = (mkey == bind->key);
+        bool exact   = (bind->mods == mods);
+        bool any     = (bind->mods == ModAny);
+        bool oneplus = ((bind->mods == ModOneOrMore) && (mods & ModOneOrMore));
+        if (match && (exact || oneplus || any)) {
             bind->action();
             return;
         }
diff --git a/xedit.c b/xedit.c
index 28225e4e6c491206563c0197910e177e9d8abfac..5d659a6359d0dcda4b50ca81d7717d6838e38119 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -20,6 +20,7 @@ typedef struct {
 static Tag Builtins[];
 static int SearchDir = DOWN;
 static char* SearchTerm = NULL;
+static size_t Marks[10] = {0};
 
 /* Tag/Cmd Execution
  ******************************************************************************/
@@ -379,10 +380,19 @@ static void newline(void) {
     view_insert(view, true, '\n');
 }
 
-void highlight(void) {
+static void highlight(void) {
     view_selctx(win_view(FOCUSED));
 }
 
+static void jumpmark(void) {
+    int mark = (win_getkey() - '0');
+    assert(mark < 10);
+    if (x11_keymodsset(ModAlt))
+        Marks[mark] = win_view(FOCUSED)->selection.end;
+    else
+        view_jumpto(win_view(FOCUSED), false, Marks[mark]);
+}
+
 /* Main Routine
  ******************************************************************************/
 static Tag Builtins[] = {
@@ -440,23 +450,30 @@ static KeyBinding Bindings[] = {
     { ModAny,  KEY_DELETE,    delete    },
     { ModAny,  KEY_BACKSPACE, backspace },
 
+    /* Marks Handling */
+    { ModOneOrMore, '0', jumpmark },
+    { ModOneOrMore, '1', jumpmark },
+    { ModOneOrMore, '2', jumpmark },
+    { ModOneOrMore, '3', jumpmark },
+    { ModOneOrMore, '4', jumpmark },
+    { ModOneOrMore, '5', jumpmark },
+    { ModOneOrMore, '6', jumpmark },
+    { ModOneOrMore, '7', jumpmark },
+    { ModOneOrMore, '8', jumpmark },
+    { ModOneOrMore, '9', jumpmark },
+
     /* Implementation Specific */
     { ModNone,                 KEY_ESCAPE, select_prev  },
     { ModCtrl,                 't',        change_focus },
     { ModCtrl,                 'q',        quit         },
     { ModCtrl,                 'h',        highlight    },
-    { ModCtrl,                 'f',        search       },
-    { ModCtrl|ModShift,        'f',        search       },
-    { ModCtrl|ModAlt,          'f',        search       },
-    { ModCtrl|ModAlt|ModShift, 'f',        search       },
+    { ModOneOrMore,            'f',        search       },
     { ModCtrl,                 'd',        execute      },
     { ModCtrl,                 'o',        open_file    },
     { ModCtrl,                 'p',        pick_ctag    },
-    { ModCtrl,                 'g',        goto_ctag    },
-    { ModCtrl|ModShift,        'g',        goto_ctag    },
+    { ModOneOrMore,            'g',        goto_ctag    },
     { ModCtrl,                 'n',        new_win      },
-    { ModCtrl,                 '\n',       newline      },
-    { ModCtrl|ModShift,        '\n',       newline      },
+    { ModOneOrMore,            '\n',       newline      },
     { ModCtrl,                 ' ',        complete     },
     { 0, 0, 0 }
 };