On Mi, 24 Jul 2013, Jeroen Budts wrote: > I have a feature request for gvim, I'm not sure if I should ask it > here or on the dev list? > Would it be possible to add support for strikethrough text in Gvim? > Since gvim can already display bold, italic, underline and undercurl > text I guess it can't be too difficult to add this to gvim? > > Strikethrough text would be useful in multiple occasions imho. For > example in Vimwiki you can add ~~some text~~ which will be rendered > to html as strikethrough, so it would be nice if gvim could actually > show it as strikethrough (exactly the same as currently for *bold* > and _italic_ text in vimwiki). > Or for example to clearly indicate removed text when viewing a diff. > > Jeroen
This sounds like an interesting idea and I thought, it would be fun, to check how easy it would be to implement it. Attached is a patch to try out. It seems to work for me with GTK and Motif Gui. I am a Unix gui and can't say for sure the code for Windows and Mac is actually correct and works, though. Secondly, I am unsure about the changes to term.c and term.h I don't know, if these changes are actually needed, so I simply took the undercurl code as an example and changed it so it would fit for strikethrough. regards, Christian -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -5823,6 +5823,7 @@ "standout" "1" if standout "underline" "1" if underlined "undercurl" "1" if undercurled + "strike" "1" if strikethrough Example (echoes the color of the syntax item under the cursor): > diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -4459,12 +4459,14 @@ *bold* *underline* *undercurl* *inverse* *italic* *standout* + *strikethrough* term={attr-list} *attr-list* *highlight-term* *E418* attr-list is a comma separated list (without spaces) of the following items (in any order): bold underline undercurl not always available + strikethrough not always available reverse inverse same as reverse italic @@ -4474,8 +4476,8 @@ Note that "bold" can be used here and by using a bold font. They have the same effect. "undercurl" is a curly underline. When "undercurl" is not possible - then "underline" is used. In general "undercurl" is only available in - the GUI. The color is set with |highlight-guisp|. + then "underline" is used. In general "undercurl" and "strikethrough" + is only available in the GUI. The color is set with |highlight-guisp|. start={term-list} *highlight-start* *E422* stop={term-list} *term-list* *highlight-stop* @@ -4633,7 +4635,8 @@ guibg={color-name} *highlight-guibg* guisp={color-name} *highlight-guisp* These give the foreground (guifg), background (guibg) and special - (guisp) color to use in the GUI. "guisp" is used for undercurl. + (guisp) color to use in the GUI. "guisp" is used for undercurl and + strikethrough. There are a few special names: NONE no color (transparent) bg use normal background color diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -17835,6 +17835,10 @@ case 's': if (TOLOWER_ASC(what[1]) == 'p') /* sp[#] */ p = highlight_color(id, what, modec); + /* strikeout */ + else if (TOLOWER_ASC(what[1]) == 't' && + TOLOWER_ASC(what[2]) == 'r') + p = highlight_has_attr(id, HL_STRIKETHROUGH, modec); else /* standout */ p = highlight_has_attr(id, HL_STANDOUT, modec); break; diff --git a/src/gui.c b/src/gui.c --- a/src/gui.c +++ b/src/gui.c @@ -2382,6 +2382,7 @@ /* Do we underline the text? */ if (hl_mask_todo & HL_UNDERLINE) draw_flags |= DRAW_UNDERL; + #else /* Do we underline the text? */ if ((hl_mask_todo & HL_UNDERLINE) @@ -2395,6 +2396,10 @@ if (hl_mask_todo & HL_UNDERCURL) draw_flags |= DRAW_UNDERC; + /* Do we strikethrough the text? */ + if (hl_mask_todo & HL_STRIKETHROUGH) + draw_flags |= DRAW_STRIKE; + /* Do we draw transparently? */ if (flags & GUI_MON_TRS_CURSOR) draw_flags |= DRAW_TRANSP; diff --git a/src/gui.h b/src/gui.h --- a/src/gui.h +++ b/src/gui.h @@ -142,6 +142,7 @@ # define DRAW_ITALIC 0x10 /* draw italic text */ #endif #define DRAW_CURSOR 0x20 /* drawing block cursor (win32) */ +#define DRAW_STRIKE 0x40 /* strikethrough */ /* For our own tearoff menu item */ #define TEAR_STRING "-->Detach" diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c --- a/src/gui_gtk_x11.c +++ b/src/gui_gtk_x11.c @@ -4883,6 +4883,15 @@ FILL_X(col), y, FILL_X(col + cells) - 1, y); } + + /* Draw a strikethrough line */ + if (flags & DRAW_STRIKE) + { + gdk_gc_set_foreground(gui.text_gc, gui.spcolor); + gdk_draw_line(gui.drawarea->window, gui.text_gc, + FILL_X(col), y + 1 - gui.char_height/2, FILL_X(col + cells), y + 1 - gui.char_height/2); + gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); + } } int diff --git a/src/gui_mac.c b/src/gui_mac.c --- a/src/gui_mac.c +++ b/src/gui_mac.c @@ -4043,6 +4043,11 @@ MoveTo(FILL_X(col), FILL_Y(row + 1) - 1); LineTo(FILL_X(col + len) - 1, FILL_Y(row + 1) - 1); } + if (flags & DRAW_STRIKE) + { + MoveTo(FILL_X(col), FILL_Y(row + 1) - gui.char_height/2); + LineTo(FILL_X(col + len) - 1, FILL_Y(row + 1) - gui.char_height/2); + } } if (flags & DRAW_UNDERC) diff --git a/src/gui_w32.c b/src/gui_w32.c --- a/src/gui_w32.c +++ b/src/gui_w32.c @@ -2492,6 +2492,18 @@ DeleteObject(SelectObject(s_hdc, old_pen)); } + /* Strikethrough */ + if (flags & DRAW_STRIKE) + { + hpen = CreatePen(PS_SOLID, 1, gui.currSpColor); + old_pen = SelectObject(s_hdc, hpen); + y = FILL_Y(row + 1) - gui.char_height/2; + MoveToEx(s_hdc, FILL_X(col), y, NULL); + /* Note: LineTo() excludes the last pixel in the line. */ + LineTo(s_hdc, FILL_X(col + len), y); + DeleteObject(SelectObject(s_hdc, old_pen)); + } + /* Undercurl */ if (flags & DRAW_UNDERC) { diff --git a/src/gui_x11.c b/src/gui_x11.c --- a/src/gui_x11.c +++ b/src/gui_x11.c @@ -2676,6 +2676,16 @@ y, FILL_X(col + cells) - 1, y); } + if (flags & DRAW_STRIKE) + { + int y = FILL_Y(row + 1) - gui.char_height/2; + + XSetForeground(gui.dpy, gui.text_gc, prev_sp_color); + XDrawLine(gui.dpy, gui.wid, gui.text_gc, FILL_X(col), + y, FILL_X(col + cells) - 1, y); + XSetForeground(gui.dpy, gui.text_gc, prev_fg_color); + } + #ifdef FEAT_XFONTSET if (current_fontset != NULL) XSetClipMask(gui.dpy, gui.text_gc, None); diff --git a/src/syntax.c b/src/syntax.c --- a/src/syntax.c +++ b/src/syntax.c @@ -82,10 +82,10 @@ * following names, separated by commas (but no spaces!). */ static char *(hl_name_table[]) = - {"bold", "standout", "underline", "undercurl", + {"bold", "standout", "underline", "undercurl", "strikethrough", "italic", "reverse", "inverse", "NONE"}; static int hl_attr_table[] = - {HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERCURL, HL_ITALIC, HL_INVERSE, HL_INVERSE, 0}; + {HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERCURL, HL_STRIKETHROUGH, HL_ITALIC, HL_INVERSE, HL_INVERSE, 0}; static int get_attr_entry __ARGS((garray_T *table, attrentry_T *aep)); static void syn_unadd_group __ARGS((void)); diff --git a/src/term.c b/src/term.c --- a/src/term.c +++ b/src/term.c @@ -195,6 +195,8 @@ {(int)KS_US, IF_EB("\033|8h", ESC_STR "|8h")}, /* HL_UNDERLINE */ {(int)KS_UCE, IF_EB("\033|8C", ESC_STR "|8C")}, /* HL_UNDERCURL */ {(int)KS_UCS, IF_EB("\033|8c", ESC_STR "|8c")}, /* HL_UNDERCURL */ + {(int)KS_STE, IF_EB("\033|4C", ESC_STR "|4C")}, /* HL_STRIKETHROUGH */ + {(int)KS_STS, IF_EB("\033|4c", ESC_STR "|4c")}, /* HL_STRIKETHROUGH */ {(int)KS_CZR, IF_EB("\033|4H", ESC_STR "|4H")}, /* HL_ITALIC */ {(int)KS_CZH, IF_EB("\033|4h", ESC_STR "|4h")}, /* HL_ITALIC */ {(int)KS_VB, IF_EB("\033|f", ESC_STR "|f")}, diff --git a/src/term.h b/src/term.h --- a/src/term.h +++ b/src/term.h @@ -51,6 +51,8 @@ KS_US, /* underscore (underline) mode */ KS_UCE, /* exit undercurl mode */ KS_UCS, /* undercurl mode */ + KS_STE, /* exit strikethrough mode */ + KS_STS, /* strikethrough mode */ KS_MS, /* save to move cur in reverse mode */ KS_CM, /* cursor motion */ KS_SR, /* scroll reverse (backward) */ @@ -129,6 +131,8 @@ #define T_US (term_str(KS_US)) /* underscore (underline) mode */ #define T_UCE (term_str(KS_UCE)) /* exit undercurl mode */ #define T_UCS (term_str(KS_UCS)) /* undercurl mode */ +#define T_STE (term_str(KS_STE)) /* exit strikethrough mode */ +#define T_STS (term_str(KS_STS)) /* strikethrough mode */ #define T_MS (term_str(KS_MS)) /* save to move cur in reverse mode */ #define T_CM (term_str(KS_CM)) /* cursor motion */ #define T_SR (term_str(KS_SR)) /* scroll reverse (backward) */ diff --git a/src/vim.h b/src/vim.h --- a/src/vim.h +++ b/src/vim.h @@ -662,7 +662,8 @@ #define HL_UNDERLINE 0x08 #define HL_UNDERCURL 0x10 #define HL_STANDOUT 0x20 -#define HL_ALL 0x3f +#define HL_STRIKETHROUGH 0x40 +#define HL_ALL 0x4f /* special attribute addition: Put message in history */ #define MSG_HIST 0x1000