added primitive Shell-script mode in module script.c
added extensions .idl .json .pcc for c-mode match perl scripts on #!.*bin/perl.* added DisplayState.space_width added do_electric_filename on minibuf_mode / and ~ expand ~ syntax upon completing filename entry in minibuf enable undo in minibuffer
This commit is contained in:
parent
28397f424f
commit
cb8abc29fc
7 changed files with 205 additions and 22 deletions
2
Makefile
2
Makefile
|
|
@ -117,7 +117,7 @@ endif
|
|||
|
||||
ifdef CONFIG_ALL_MODES
|
||||
OBJS+= unihex.o clang.o latex-mode.o xml.o bufed.o \
|
||||
makemode.o perl.o htmlsrc.o
|
||||
makemode.o perl.o htmlsrc.o script.o
|
||||
ifndef CONFIG_WIN32
|
||||
OBJS+= shell.o dired.o
|
||||
endif
|
||||
|
|
|
|||
2
clang.c
2
clang.c
|
|
@ -45,7 +45,7 @@ static const char *c_mode_types =
|
|||
"_Bool|_Complex|_Imaginary|";
|
||||
|
||||
static const char *c_mode_extensions =
|
||||
"c|h|y|e|cc|cs|cpp|cxx|hpp|hxx|jav|java|js|qe|";
|
||||
"c|h|y|e|cc|cs|cpp|cxx|hpp|hxx|idl|jav|java|js|qe|json|pcc";
|
||||
|
||||
#if 0
|
||||
static int get_c_identifier(char *buf, int buf_size, unsigned int *p)
|
||||
|
|
|
|||
2
perl.c
2
perl.c
|
|
@ -337,7 +337,7 @@ static int perl_mode_probe(ModeProbeData *p)
|
|||
return 80;
|
||||
|
||||
if (p->buf[0] == '#' && p->buf[1] == '!' &&
|
||||
memstr(p->buf, p->line_len, "/usr/bin/perl"))
|
||||
memstr(p->buf, p->line_len, "bin/perl"))
|
||||
return 80;
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
33
qe.c
33
qe.c
|
|
@ -2317,7 +2317,8 @@ void display_init(DisplayState *s, EditState *e, enum DisplayType do_disp)
|
|||
glyph_width(e->screen, font, '\\'));
|
||||
s->eol_width = max(s->eol_width, glyph_width(e->screen, font, '$'));
|
||||
s->default_line_height = font->ascent + font->descent;
|
||||
s->tab_width = glyph_width(e->screen, font, ' ') * e->tab_size;
|
||||
s->space_width = glyph_width(e->screen, font, ' ');
|
||||
s->tab_width = s->space_width * e->tab_size;
|
||||
s->width = e->width - s->eol_width;
|
||||
s->height = e->height;
|
||||
s->hex_mode = e->hex_mode;
|
||||
|
|
@ -2776,6 +2777,7 @@ static void flush_fragment(DisplayState *s)
|
|||
s->x = 0;
|
||||
if (s->edit_state->line_numbers) {
|
||||
/* should skip line number column if present */
|
||||
//s->x = s->space_width * 8;
|
||||
}
|
||||
if (len1 > 0) {
|
||||
memmove(s->fragments, frag, sizeof(TextFragment));
|
||||
|
|
@ -2784,7 +2786,7 @@ static void flush_fragment(DisplayState *s)
|
|||
frag->line_index = 0;
|
||||
frag->len = len1;
|
||||
s->nb_fragments = 1;
|
||||
s->x = w1;
|
||||
s->x += w1;
|
||||
}
|
||||
keep_line_chars(s, len1);
|
||||
}
|
||||
|
|
@ -2801,6 +2803,10 @@ static void flush_fragment(DisplayState *s)
|
|||
(s->nb_fragments - s->word_index) * sizeof(TextFragment));
|
||||
s->nb_fragments -= s->word_index;
|
||||
s->x = 0;
|
||||
if (s->edit_state->line_numbers) {
|
||||
/* skip line number column if present */
|
||||
//s->x = s->space_width * 8;
|
||||
}
|
||||
for (i = 0; i < s->nb_fragments; i++) {
|
||||
s->fragments[i].line_index -= index;
|
||||
s->x += s->fragments[i].width;
|
||||
|
|
@ -4477,11 +4483,18 @@ void file_completion(CompleteState *cp)
|
|||
char path[MAX_FILENAME_SIZE];
|
||||
char file[MAX_FILENAME_SIZE];
|
||||
char filename[MAX_FILENAME_SIZE];
|
||||
char *current;
|
||||
FindFileState *ffst;
|
||||
const char *base;
|
||||
int len;
|
||||
|
||||
splitpath(path, sizeof(path), file, sizeof(file), cp->current);
|
||||
current = cp->current;
|
||||
if (*current == '~') {
|
||||
canonicalize_absolute_path(filename, sizeof(filename), cp->current);
|
||||
current = filename;
|
||||
}
|
||||
|
||||
splitpath(path, sizeof(path), file, sizeof(file), current);
|
||||
pstrcat(file, sizeof(file), "*");
|
||||
|
||||
ffst = find_file_open(*path ? path : ".", file);
|
||||
|
|
@ -4679,6 +4692,18 @@ void do_completion(EditState *s)
|
|||
complete_end(&cs);
|
||||
}
|
||||
|
||||
void do_electric_filename(EditState *s, int key)
|
||||
{
|
||||
int c, offset;
|
||||
|
||||
if (completion_function == file_completion) {
|
||||
c = eb_prevc(s->b, s->offset, &offset);
|
||||
if (c == '/')
|
||||
eb_delete(s->b, 0, s->offset);
|
||||
}
|
||||
do_char(s, key, 1);
|
||||
}
|
||||
|
||||
/* space does completion only if a completion method is defined */
|
||||
void do_completion_space(EditState *s)
|
||||
{
|
||||
|
|
@ -4868,7 +4893,7 @@ void minibuffer_edit(const char *input, const char *prompt,
|
|||
minibuffer_cb = cb;
|
||||
minibuffer_opaque = opaque;
|
||||
|
||||
b = eb_new("*minibuf*", BF_SYSTEM);
|
||||
b = eb_new("*minibuf*", BF_SYSTEM | BF_SAVELOG);
|
||||
|
||||
s = edit_new(b, 0, qs->screen->height - qs->status_height,
|
||||
qs->screen->width, qs->status_height, 0);
|
||||
|
|
|
|||
31
qe.h
31
qe.h
|
|
@ -1289,37 +1289,37 @@ typedef struct TextFragment {
|
|||
#define CHAR_MASK ((1 << STYLE_SHIFT) - 1)
|
||||
|
||||
struct DisplayState {
|
||||
int do_disp; /* true if real display */
|
||||
int width; /* display window width */
|
||||
int height; /* display window height */
|
||||
int eol_width; /* width of eol char */
|
||||
int do_disp; /* true if real display */
|
||||
int width; /* display window width */
|
||||
int height; /* display window height */
|
||||
int eol_width; /* width of eol char */
|
||||
int default_line_height; /* line height if no chars */
|
||||
int tab_width; /* width of tabulation */
|
||||
int x_disp; /* starting x display */
|
||||
int x; /* current x position */
|
||||
int y; /* current y position */
|
||||
int line_num; /* current text line number */
|
||||
int cur_hex_mode; /* true if current char is in hex mode */
|
||||
int hex_mode; /* hex mode from edit_state, -1 if all chars wanted */
|
||||
int space_width; /* width of space character */
|
||||
int tab_width; /* width of tabulation */
|
||||
int x_disp; /* starting x display */
|
||||
int x; /* current x position */
|
||||
int y; /* current y position */
|
||||
int line_num; /* current text line number */
|
||||
int cur_hex_mode; /* true if current char is in hex mode */
|
||||
int hex_mode; /* hex mode from edit_state, -1 if all chars wanted */
|
||||
void *cursor_opaque;
|
||||
int (*cursor_func)(struct DisplayState *,
|
||||
int offset1, int offset2, int line_num,
|
||||
int x, int y, int w, int h, int hex_mode);
|
||||
int eod; /* end of display requested */
|
||||
int eod; /* end of display requested */
|
||||
/* if base == RTL, then all x are equivalent to width - x */
|
||||
DirType base;
|
||||
int embedding_level_max;
|
||||
int wrap;
|
||||
int eol_reached;
|
||||
EditState *edit_state;
|
||||
int style; /* css display style */
|
||||
int style; /* css display style */
|
||||
|
||||
/* fragment buffers */
|
||||
TextFragment fragments[MAX_SCREEN_WIDTH];
|
||||
int nb_fragments;
|
||||
int last_word_space; /* true if last word was a space */
|
||||
int word_index; /* fragment index of the start of the current
|
||||
word */
|
||||
int word_index; /* fragment index of the start of the current word */
|
||||
/* line char (in fact glyph) buffer */
|
||||
unsigned int line_chars[MAX_SCREEN_WIDTH];
|
||||
short line_char_widths[MAX_SCREEN_WIDTH];
|
||||
|
|
@ -1632,6 +1632,7 @@ void do_define_kbd_macro(EditState *s, const char *name, const char *keys,
|
|||
void edit_attach(EditState *s, EditState **ep);
|
||||
void do_completion(EditState *s);
|
||||
void do_completion_space(EditState *s);
|
||||
void do_electric_filename(EditState *s, int key);
|
||||
void minibuf_complete_scroll_up_down(EditState *s, int dir);
|
||||
void do_history(EditState *s, int dir);
|
||||
void do_minibuffer_get_binary(EditState *s);
|
||||
|
|
|
|||
|
|
@ -385,6 +385,10 @@ CmdDef minibuffer_commands[] = {
|
|||
"previous-history-element", do_history, -1)
|
||||
CMD1( KEY_CTRL('n'), KEY_DOWN,
|
||||
"next-history-element", do_history, 1)
|
||||
CMDV( '/', KEY_NONE,
|
||||
"electric-slash", do_electric_filename, ESi, '/', "*v")
|
||||
CMDV( '~', KEY_NONE,
|
||||
"electric-tilde", do_electric_filename, ESi, '~', "*v")
|
||||
CMD_DEF_END,
|
||||
};
|
||||
|
||||
|
|
|
|||
153
script.c
Normal file
153
script.c
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* Shell script mode for QEmacs.
|
||||
*
|
||||
* Copyright (c) 2000-2008 Charlie Gordon.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "qe.h"
|
||||
|
||||
static const char *script_mode_extensions = "sh|bash|zsh";
|
||||
|
||||
/*---------------- Perl colors ----------------*/
|
||||
|
||||
enum {
|
||||
SCRIPT_TEXT = QE_STYLE_DEFAULT,
|
||||
SCRIPT_COMMENT = QE_STYLE_COMMENT,
|
||||
SCRIPT_PREPROCESS = QE_STYLE_PREPROCESS,
|
||||
SCRIPT_COMMAND = QE_STYLE_FUNCTION,
|
||||
SCRIPT_VARIABLE = QE_STYLE_TYPE,
|
||||
SCRIPT_STRING = QE_STYLE_STRING,
|
||||
SCRIPT_BACKTICK = QE_STYLE_STRING_Q,
|
||||
};
|
||||
|
||||
static int script_var(const unsigned int *str, int j, int n)
|
||||
{
|
||||
for (; j < n; j++) {
|
||||
if (qe_isalnum_(str[j]) || str[j] == '-')
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
static void script_colorize_line(unsigned int *str, int n, int *statep,
|
||||
__unused__ int state_only)
|
||||
{
|
||||
int i = 0, j, style;
|
||||
|
||||
style = SCRIPT_COMMAND;
|
||||
|
||||
while (i < n) {
|
||||
switch (str[i]) {
|
||||
case '#':
|
||||
if (i > 0 && str[i - 1] == '$')
|
||||
break;
|
||||
style = SCRIPT_COMMENT;
|
||||
if (str[i + 1] == '!')
|
||||
style = SCRIPT_PREPROCESS;
|
||||
set_color(str + i, str + n, style);
|
||||
i = n;
|
||||
continue;
|
||||
case '`':
|
||||
style = SCRIPT_BACKTICK;
|
||||
goto has_string;
|
||||
case '\'':
|
||||
case '"':
|
||||
style = SCRIPT_STRING;
|
||||
has_string:
|
||||
/* parse string const */
|
||||
for (j = i + 1; j < n; j++) {
|
||||
if (str[j] == str[i]) {
|
||||
j++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
set_color(str + i, str + j, style);
|
||||
i = j;
|
||||
continue;
|
||||
case ' ':
|
||||
case '\t':
|
||||
break;
|
||||
default:
|
||||
j = script_var(str, i, n);
|
||||
if (j > i) {
|
||||
while (qe_isblank(str[j]))
|
||||
j++;
|
||||
if (str[j] == '=')
|
||||
style = SCRIPT_VARIABLE;
|
||||
set_color(str + i, str + j, style);
|
||||
style = SCRIPT_TEXT;
|
||||
i = j;
|
||||
continue;
|
||||
}
|
||||
// Should support << syntax
|
||||
// Should support $ syntax
|
||||
style = SCRIPT_TEXT;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
static int script_mode_probe(ModeProbeData *p)
|
||||
{
|
||||
if (match_extension(p->filename, script_mode_extensions))
|
||||
return 80;
|
||||
|
||||
if (p->buf[0] == '#') {
|
||||
if (p->buf[1] == '!')
|
||||
return 60;
|
||||
if (p->buf[1] == ' ')
|
||||
return 30;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int script_mode_init(EditState *s, ModeSavedData *saved_data)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = text_mode_init(s, saved_data);
|
||||
if (ret)
|
||||
return ret;
|
||||
set_colorize_func(s, script_colorize_line);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* specific script commands */
|
||||
static CmdDef script_commands[] = {
|
||||
CMD_DEF_END,
|
||||
};
|
||||
|
||||
static ModeDef script_mode;
|
||||
|
||||
static int script_init(void)
|
||||
{
|
||||
/* c mode is almost like the text mode, so we copy and patch it */
|
||||
memcpy(&script_mode, &text_mode, sizeof(ModeDef));
|
||||
script_mode.name = "Shell-script";
|
||||
script_mode.mode_probe = script_mode_probe;
|
||||
script_mode.mode_init = script_mode_init;
|
||||
|
||||
qe_register_mode(&script_mode);
|
||||
qe_register_cmd_table(script_commands, &script_mode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
qe_module_init(script_init);
|
||||
Loading…
Add table
Add a link
Reference in a new issue