[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs bufed.c buffer.c charset.c clang.c dired...
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs bufed.c buffer.c charset.c clang.c dired... |
Date: |
Thu, 03 Jan 2008 18:31:25 +0000 |
CVSROOT: /cvsroot/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 08/01/03 18:31:25
Modified files:
. : bufed.c buffer.c charset.c clang.c dired.c
input.c latex-mode.c qe.c qe.h qeconfig.h
shell.c util.c
Log message:
renamed do_set_mode -> edit_set_mode
use match_extension in mode probe functions
pass move indicator to do_return, removed do_open_line
renamed do_cmd_set_mode -> do_set_mode for consistency
separated strfind and strcasefind, optimized implementation
published register_input_method
unpublished input_methods
optimized KeyDef structure layout
changed eb_search arguments
used eb_delete_range
comments, remarks
better tests on fread failures
set buffer to read-only upon loading non writable file
do_insert_file tests for failure
set mark at beginning of inserted block and offset at the end
fixed search for word boundary case
made raw_load_buffer1 return number of bytes read, of -1 on error
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/bufed.c?cvsroot=qemacs&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/qemacs/charset.c?cvsroot=qemacs&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/qemacs/dired.c?cvsroot=qemacs&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/qemacs/input.c?cvsroot=qemacs&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.58&r2=1.59
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.54&r2=1.55
http://cvs.savannah.gnu.org/viewcvs/qemacs/qeconfig.h?cvsroot=qemacs&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.31&r2=1.32
Patches:
Index: bufed.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/bufed.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- bufed.c 3 Jan 2008 09:51:30 -0000 1.11
+++ bufed.c 3 Jan 2008 18:31:24 -0000 1.12
@@ -176,7 +176,7 @@
width = qs->width / 5;
e = insert_window_left(b, width, WF_MODELINE);
- do_set_mode(e, &bufed_mode, NULL);
+ edit_set_mode(e, &bufed_mode, NULL);
bs = e->mode_data;
if (argval != NO_ARG) {
Index: buffer.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/buffer.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- buffer.c 3 Jan 2008 09:51:30 -0000 1.29
+++ buffer.c 3 Jan 2008 18:31:24 -0000 1.30
@@ -1326,23 +1326,26 @@
}
#endif
+/* CG: returns number of bytes read, or -1 upon read error */
int raw_load_buffer1(EditBuffer *b, FILE *f, int offset)
{
- int len;
unsigned char buf[IOBUF_SIZE];
+ int len, size;
//put_status(NULL, "loading %s", filename);
+ size = 0;
for (;;) {
len = fread(buf, 1, IOBUF_SIZE, f);
- if (len < 0)
+ if (len <= 0 && ferror(f))
return -1;
if (len == 0)
break;
eb_insert(b, offset, buf, len);
offset += len;
+ size += len;
}
//put_status(NULL, "");
- return 0;
+ return size;
}
#ifdef WIN32
Index: charset.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/charset.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- charset.c 3 Jan 2008 09:51:30 -0000 1.14
+++ charset.c 3 Jan 2008 18:31:24 -0000 1.15
@@ -287,7 +287,7 @@
for (charset = first_charset; charset != NULL; charset = charset->next) {
if (!strxcmp(charset->name, name)
- || strfind(charset->aliases, name, 1)) {
+ || strcasefind(charset->aliases, name)) {
return charset;
}
}
Index: clang.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/clang.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- clang.c 3 Jan 2008 09:51:30 -0000 1.23
+++ clang.c 3 Jan 2008 18:31:24 -0000 1.24
@@ -222,7 +222,7 @@
} while (qe_isalnum_(c));
kbuf[klen] = '\0';
- if (strfind(c_mode_keywords, kbuf, 0)) {
+ if (strfind(c_mode_keywords, kbuf)) {
set_color(p_start, p, QE_STYLE_KEYWORD);
continue;
}
@@ -234,7 +234,7 @@
while (*p2 == '*' || qe_isblank(*p2))
p2++;
- if (strfind(c_mode_types, kbuf, 0)
+ if (strfind(c_mode_types, kbuf)
|| (klen > 2 && kbuf[klen - 2] == '_' && kbuf[klen - 1] ==
't')) {
/* c type */
/* if not cast, assume type declaration */
Index: dired.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/dired.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- dired.c 3 Jan 2008 09:51:30 -0000 1.15
+++ dired.c 3 Jan 2008 18:31:25 -0000 1.16
@@ -514,7 +514,7 @@
width = qs->width / 5;
e = insert_window_left(b, width, WF_MODELINE);
- do_set_mode(e, &dired_mode, NULL);
+ edit_set_mode(e, &dired_mode, NULL);
hs = e->mode_data;
e1 = find_window(e, KEY_RIGHT);
Index: input.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/input.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- input.c 3 Jan 2008 09:51:31 -0000 1.15
+++ input.c 3 Jan 2008 18:31:25 -0000 1.16
@@ -23,7 +23,7 @@
#include <sys/mman.h>
#endif
-InputMethod *input_methods;
+static InputMethod *input_methods;
static int default_input(__unused__ int *match_buf,
__unused__ int match_buf_size,
@@ -71,7 +71,7 @@
"unicode", unicode_input, NULL, NULL,
};
-static void register_input_method(InputMethod *m)
+void register_input_method(InputMethod *m)
{
InputMethod **p;
Index: latex-mode.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- latex-mode.c 3 Jan 2008 09:51:31 -0000 1.21
+++ latex-mode.c 3 Jan 2008 18:31:25 -0000 1.22
@@ -125,14 +125,10 @@
static int latex_mode_probe(ModeProbeData *p)
{
- const char *r;
-
/* currently, only use the file extension */
- r = extension(p->filename);
- if (*r) {
- if (strfind("|tex|", r + 1, 1))
+ if (match_extension(p->filename, "tex"))
return 100;
- }
+
return 0;
}
Index: qe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- qe.c 3 Jan 2008 09:51:31 -0000 1.58
+++ qe.c 3 Jan 2008 18:31:25 -0000 1.59
@@ -47,7 +47,7 @@
static void qe_key_process(int key);
ModeSavedData *generic_mode_save_data(EditState *s);
-void generic_text_display(EditState *s);
+static void generic_text_display(EditState *s);
static void display1(DisplayState *s);
#ifndef CONFIG_TINY
static void save_selection(void);
@@ -106,7 +106,7 @@
def->key = def->alt_key = KEY_NONE;
def->sig = CMD_ESs;
def->val = 0;
- def->action.ESs = do_cmd_set_mode;
+ def->action.ESs = do_set_mode;
qe_register_cmd_table(def, NULL);
}
}
@@ -181,8 +181,7 @@
}
/* convert compressed mappings to real ones */
-static void qe_register_binding2(int key,
- CmdDef *d, ModeDef *m)
+static void qe_register_binding2(int key, CmdDef *d, ModeDef *m)
{
int nb_keys;
unsigned int keys[3];
@@ -207,6 +206,7 @@
/* if mode is non NULL, the defined keys are only active in this mode */
void qe_register_cmd_table(CmdDef *cmds, const char *mode)
{
+ QEmacsState *qs = &qe_state;
CmdDef **ld, *d;
ModeDef *m;
@@ -215,7 +215,7 @@
m = find_mode(mode);
/* find last command table */
- for (ld = &qe_state.first_cmd;;) {
+ for (ld = &qs->first_cmd;;) {
d = *ld;
if (d == NULL) {
/* link new command table */
@@ -304,8 +304,8 @@
#define MAX_KEYS 10
-void do_global_set_key(__unused__ EditState *s,
- const char *keystr, const char *cmd_name)
+void do_global_set_key(EditState *s, const char *keystr,
+ const char *cmd_name)
{
int nb_keys;
unsigned int keys[MAX_KEYS];
@@ -744,8 +744,7 @@
if (argval == NO_ARG) {
eb_prevc(s->b, s->offset, &offset1);
if (offset1 < s->offset) {
- eb_delete(s->b, offset1, s->offset - offset1);
- s->offset = offset1;
+ s->offset = eb_delete_range(s->b, offset1, s->offset);
/* special case for composing */
if (s->compose_len > 0)
s->compose_len--;
@@ -1273,15 +1272,11 @@
/* more chars expected: do nothing and insert current key */
break;
} else {
- /* match : delete matched chars */
+ /* match: delete matched chars */
offset = s->compose_start_offset;
- offset1 = s->offset; /* save offset so that we are not disturb
- when it moves in eb_delete() */
for (i = 0; i < match_len; i++)
eb_nextc(s->b, offset, &offset);
- eb_delete(s->b, s->compose_start_offset,
- offset - s->compose_start_offset);
- s->offset = offset1 - (offset - s->compose_start_offset);
+ eb_delete_range(s->b, s->compose_start_offset, offset);
s->compose_len -= match_len;
umemmove(s->compose_buf, s->compose_buf + match_len,
s->compose_len);
@@ -1290,8 +1285,9 @@
key = match_buf[i];
len = unicode_to_charset(buf, key, s->b->charset);
eb_insert(s->b, s->compose_start_offset, buf, len);
- s->offset += len;
s->compose_start_offset += len;
+ /* should only bump s->offset if at insert point */
+ s->offset += len;
}
/* if some compose chars are left, we iterate */
if (s->compose_len == 0)
@@ -1299,12 +1295,8 @@
}
}
} else {
- if (cur_len == len) {
- eb_write(s->b, s->offset, buf, len);
- } else {
- eb_delete(s->b, s->offset, cur_len);
- eb_insert(s->b, s->offset, buf, len);
- }
+ eb_replace(s->b, s->offset, cur_len, buf, len);
+ /* adjust offset because in inserting at point */
s->offset += len;
}
}
@@ -1326,8 +1318,7 @@
return;
/* CG: why not insert special keys as well? */
- if (!KEY_SPECIAL(key) ||
- (key >= 0 && key <= 31)) {
+ if (!KEY_SPECIAL(key) || (key >= 0 && key <= 31)) {
do_char(s, key, qa->argval);
edit_display(s->qe_state);
dpy_flush(&global_screen);
@@ -1353,37 +1344,33 @@
void do_tab(EditState *s, int argval)
{
+ /* CG: should do smart complete, smart indent, insert tab */
do_char(s, 9, argval);
}
-void do_open_line(EditState *s)
+void do_return(EditState *s, int move)
{
- u8 ch;
-
if (s->b->flags & BF_READONLY)
return;
- ch = '\n';
- eb_insert(s->b, s->offset, &ch, 1);
-}
-
-void do_return(EditState *s)
-{
- do_open_line(s);
- s->offset++;
+ eb_insert(s->b, s->offset, "\n", 1);
+ s->offset += move;
}
void do_break(EditState *s)
{
/* well, currently nothing needs to be aborted in global context */
- /* CG: Should remove popups, sidepanes, helppanes... */
- put_status(s, "Canceled.");
+ /* CG: Should remove popups, sidepanes, helppanes...
+ * deactivate region hilite */
+ put_status(s, "Quit");
}
/* block functions */
void do_set_mark(EditState *s)
{
+ /* CG: Should have local and global mark rings */
s->b->mark = s->offset;
+ /* CG: should activate the region hilite */
put_status(s, "Mark set");
}
@@ -1520,7 +1507,7 @@
return;
}
- eb_delete(s->b, s->b->mark, s->offset - s->b->mark);
+ eb_delete_range(s->b, s->b->mark, s->offset);
if (--qs->yank_current < 0) {
/* get last yank buffer, yank ring may not be full */
@@ -1577,7 +1564,7 @@
}
-static void do_set_mode_file(EditState *s, ModeDef *m,
+static void edit_set_mode_file(EditState *s, ModeDef *m,
ModeSavedData *saved_data, FILE *f1)
{
int size, data_count;
@@ -1666,20 +1653,24 @@
qe_free(&saved_data);
}
-void do_set_mode(EditState *s, ModeDef *m, ModeSavedData *saved_data)
+void edit_set_mode(EditState *s, ModeDef *m, ModeSavedData *saved_data)
{
- do_set_mode_file(s, m, saved_data, NULL);
+ edit_set_mode_file(s, m, saved_data, NULL);
}
-void do_cmd_set_mode(EditState *s, const char *name)
+void do_set_mode(EditState *s, const char *name)
{
ModeDef *m;
m = find_mode(name);
if (m)
- do_set_mode(s, m, NULL);
+ edit_set_mode(s, m, NULL);
+ else
+ put_status(s, "No mode %s", name);
}
+/* CG: should have commands to cycle modes and charsets */
+
QECharset *read_charset(EditState *s, const char *charset_str)
{
QECharset *charset;
@@ -3108,7 +3099,7 @@
}
/* Generic display algorithm with automatic fit */
-void generic_text_display(EditState *s)
+static void generic_text_display(EditState *s)
{
CursorContext m1, *m = &m1;
DisplayState ds1, *ds = &ds1;
@@ -3539,7 +3530,7 @@
int i;
/* free allocated parameters */
- for (i = 0;i < es->nb_args; i++) {
+ for (i = 0; i < es->nb_args; i++) {
switch (es->args_type[i]) {
case CMD_ARG_STRING:
qe_free(&es->args[i].p);
@@ -3591,10 +3582,10 @@
CmdDef *d;
d = qe_find_cmd(cmd);
- if (!d) {
- put_status(s, "No match");
- } else {
+ if (d) {
exec_command(s, d, argval);
+ } else {
+ put_status(s, "No match");
}
}
@@ -3658,27 +3649,6 @@
qs->complete_refresh = 0;
}
-void do_universal_argument(__unused__ EditState *s)
-{
- /* nothing is done there (see qe_key_process()) */
-}
-
-static const char *keys_to_str(char *buf, int buf_size,
- unsigned int *keys, int nb_keys)
-{
- char buf1[64];
- int i;
-
- buf[0] = '\0';
- for (i = 0; i < nb_keys; i++) {
- keytostr(buf1, sizeof(buf1), keys[i]);
- if (i != 0)
- pstrcat(buf, buf_size, " ");
- pstrcat(buf, buf_size, buf1);
- }
- return buf;
-}
-
/* macros */
void do_start_macro(EditState *s)
@@ -3798,6 +3768,27 @@
qs->macro_keys[qs->nb_macro_keys++] = key;
}
+static const char *keys_to_str(char *buf, int buf_size,
+ unsigned int *keys, int nb_keys)
+{
+ char buf1[64];
+ int i;
+
+ buf[0] = '\0';
+ for (i = 0; i < nb_keys; i++) {
+ keytostr(buf1, sizeof(buf1), keys[i]);
+ if (i != 0)
+ pstrcat(buf, buf_size, " ");
+ pstrcat(buf, buf_size, buf1);
+ }
+ return buf;
+}
+
+void do_universal_argument(__unused__ EditState *s)
+{
+ /* nothing is done there (see qe_key_process()) */
+}
+
typedef struct QEKeyContext {
int argval;
int noargval;
@@ -3894,7 +3885,8 @@
if (key == KEY_ESC) {
c->is_escape = 1;
goto next;
- } else if (c->is_escape) {
+ } else
+ if (c->is_escape) {
compose_keys(c->keys, &c->nb_keys);
c->is_escape = 0;
}
@@ -4129,7 +4121,7 @@
b1->saved_data = s->mode->mode_save_data(s);
}
/* now we can close the mode */
- do_set_mode(s, NULL, NULL);
+ edit_set_mode(s, NULL, NULL);
}
/* now we can switch ! */
@@ -4157,7 +4149,7 @@
mode = &text_mode; /* default mode */
/* open it ! */
- do_set_mode(s, mode, saved_data);
+ edit_set_mode(s, mode, saved_data);
}
}
@@ -4285,7 +4277,7 @@
}
static const char *file_completion_ignore_extensions =
- "|bak|bin|dll|exe|o|obj|";
+ "|bak|bin|dll|exe|o|so|obj|a|gz|tgz";
void file_completion(StringArray *cs, const char *input)
{
@@ -4293,7 +4285,7 @@
char path[MAX_FILENAME_SIZE];
char file[MAX_FILENAME_SIZE];
char filename[MAX_FILENAME_SIZE];
- const char *base, *ext;
+ const char *base;
int len;
splitpath(path, sizeof(path), file, sizeof(file), input);
@@ -4313,8 +4305,7 @@
if (!len || base[len - 1] == '~')
continue;
/* ignore known output file extensions */
- ext = extension(base);
- if (*ext && strfind(file_completion_ignore_extensions, ext + 1, 1))
+ if (match_extension(base, file_completion_ignore_extensions))
continue;
/* stat the file to find out if it's a directory.
@@ -4406,7 +4397,7 @@
len = eb_get_contents(s->b, input, sizeof(input));
memset(&cs, 0, sizeof(cs));
- completion_function(&cs, input);
+ (*completion_function)(&cs, input);
count = cs.nb_items;
outputs = cs.items;
#if 0
@@ -4420,6 +4411,7 @@
/* compute the longest match len */
match_len = len;
for (;;) {
+ /* Potential UTF-8 issue: should use utility function */
c = outputs[0]->str[match_len];
if (c == '\0')
break;
@@ -4446,7 +4438,7 @@
h = (h1 * 3) / 4;
e = edit_new(b, (w1 - w) / 2, (h1 - h) / 2, w, h, WF_POPUP);
/* set list mode */
- do_set_mode(e, &list_mode, NULL);
+ edit_set_mode(e, &list_mode, NULL);
do_refresh(e);
completion_popup_window = e;
}
@@ -4502,11 +4494,12 @@
static StringArray *get_history(const char *name)
{
+ QEmacsState *qs = &qe_state;
HistoryEntry *p;
if (name[0] == '\0')
return NULL;
- for (p = qe_state.first_history; p != NULL; p = p->next) {
+ for (p = qs->first_history; p != NULL; p = p->next) {
if (!strcmp(p->name, name))
return &p->history;
}
@@ -4515,8 +4508,8 @@
if (!p)
return NULL;
pstrcpy(p->name, sizeof(p->name), name);
- p->next = qe_state.first_history;
- qe_state.first_history = p;
+ p->next = qs->first_history;
+ qs->first_history = p;
return &p->history;
}
@@ -4664,7 +4657,7 @@
s = edit_new(b, 0, qs->screen->height - qs->status_height,
qs->screen->width, qs->status_height, 0);
/* Should insert at end of window list */
- do_set_mode(s, &minibuffer_mode, NULL);
+ edit_set_mode(s, &minibuffer_mode, NULL);
s->prompt = qe_strdup(prompt);
s->minibuf = 1;
s->bidir = 0;
@@ -4738,9 +4731,8 @@
w = (w1 * 4) / 5;
h = (h1 * 3) / 4;
- s = edit_new(b, (w1 - w) / 2, (h1 - h) / 2, w, h,
- WF_POPUP);
- do_set_mode(s, &less_mode, NULL);
+ s = edit_new(b, (w1 - w) / 2, (h1 - h) / 2, w, h, WF_POPUP);
+ edit_set_mode(s, &less_mode, NULL);
s->wrap = WRAP_TRUNCATE;
popup_saved_active = qs->active_window;
@@ -4881,7 +4873,7 @@
if (!b) {
put_status(s, "No buffer %s", bufname);
} else {
- /* if associated to a filename, then ask */
+ /* if modified and associated to a filename, then ask */
if (b->modified && b->filename[0] != '\0') {
snprintf(buf, sizeof(buf),
"Buffer %s modified; kill anyway? (yes or no) ", bufname);
@@ -4963,13 +4955,15 @@
static ModeDef *probe_mode(EditState *s, int mode, const uint8_t *buf,
int len, long total_size)
{
- EditBuffer *b = s->b;
+ QEmacsState *qs = s->qe_state;
+ EditBuffer *b;
ModeDef *m, *selected_mode;
ModeProbeData probe_data;
int best_probe_percent, percent;
const uint8_t *p;
- m = s->qe_state->first_mode;
+ b = s->b;
+
selected_mode = NULL;
best_probe_percent = 0;
probe_data.buf = buf;
@@ -4979,7 +4973,9 @@
probe_data.filename = b->filename;
probe_data.mode = mode;
probe_data.total_size = total_size;
+ /* CG: should pass EditState? QEmacsState ? */
+ m = qs->first_mode;
while (m != NULL) {
if (m->mode_probe) {
percent = m->mode_probe(&probe_data);
@@ -5013,32 +5009,46 @@
canonicalize_absolute_path(filename, sizeof(filename), filename1);
}
+ ///* If file already shown in window, switch to that */
+ //s1 = find_file_window(filename);
+ //if (s1 != NULL) {
+ // qs->active_window = s1;
+ // return;
+ //}
+
+ ///* Split window if window large enough and not empty */
+ //if (other_window && s->height > 10 && s->b->total_size > 0) {
+ // do_split_window(s, 0, 0);
+ // s = qs->active_window;
+ //}
+
if (kill_buffer) {
/* CG: this behaviour is not correct */
/* CG: should have a direct primitive */
do_kill_buffer(s, s->b->name);
}
- /* see if file is already edited */
+ /* If file already loaded in existing buffer, switch to that */
b = eb_find_file(filename);
- if (b) {
+ if (b != NULL) {
switch_to_buffer(s, b);
return;
}
- /* create new buffer */
+ /* Create new buffer with unique name from filename */
b = eb_new("", BF_SAVELOG);
eb_set_filename(b, filename);
- /* switch to the newly created buffer */
+ /* Switch to the newly created buffer */
switch_to_buffer(s, b);
s->offset = 0;
+ /* CG: need a default setting for this */
s->wrap = WRAP_LINE;
- /* first we try to read the first bytes of the buffer to find the
- buffer data type */
+ /* First we try to read the first block to determine the data type */
if (stat(filename, &st) < 0) {
+ /* CG: should check for wildcards and do dired */
put_status(s, "(New file)");
/* Try to determine the desired mode based on the filename.
* This avoids having to set c-mode for each new .c or .h file. */
@@ -5046,18 +5056,19 @@
selected_mode = probe_mode(s, S_IFREG, buf, 0, 0);
/* XXX: avoid loading file */
if (selected_mode)
- do_set_mode(s, selected_mode, NULL);
+ edit_set_mode(s, selected_mode, NULL);
return;
} else {
mode = st.st_mode;
buf_size = 0;
f = NULL;
+ /* CG: should check for ISDIR and do dired */
if (S_ISREG(mode)) {
f = fopen(filename, "r");
if (!f)
goto fail;
buf_size = fread(buf, 1, sizeof(buf) - 1, f);
- if (buf_size < 0) {
+ if (buf_size <= 0 && ferror(f)) {
fail1:
fclose(f);
f = NULL;
@@ -5076,9 +5087,13 @@
eb_set_charset(b, detect_charset(buf, buf_size));
/* now we can set the mode */
- do_set_mode_file(s, selected_mode, NULL, f);
+ edit_set_mode_file(s, selected_mode, NULL, f);
do_load_qerc(s, s->b->filename);
+ if (access(b->filename, W_OK)) {
+ b->flags |= BF_READONLY;
+ }
+
if (f) {
fclose(f);
}
@@ -5139,14 +5154,25 @@
void do_insert_file(EditState *s, const char *filename)
{
FILE *f;
+ int size, lastsize = s->b->total_size;
f = fopen(filename, "r");
if (!f) {
put_status(s, "Could not open file '%s'", filename);
return;
}
- raw_load_buffer1(s->b, f, s->offset);
+ /* CG: file charset will not be converted to buffer charset */
+ size = raw_load_buffer1(s->b, f, s->offset);
fclose(f);
+
+ /* mark the insert chunk */
+ s->b->mark = s->offset;
+ s->offset += s->b->total_size - lastsize;
+
+ if (size < 0) {
+ put_status(s, "Error reading '%s'", filename);
+ return;
+ }
}
void do_set_visited_file_name(EditState *s, const char *filename,
@@ -5333,18 +5359,19 @@
/* XXX: OPTIMIZE ! */
/* XXX: use UTF8 for words/chars ? */
-int eb_search(EditBuffer *b, int offset, int dir, u8 *buf, int size,
- int flags, CSSAbortFunc *abort_func, void *abort_opaque)
+int eb_search(EditBuffer *b, int offset, int dir, int flags,
+ const u8 *buf, int size,
+ CSSAbortFunc *abort_func, void *abort_opaque)
{
int total_size = b->total_size;
int i, c, lower_count, upper_count;
- unsigned char ch;
+ u8 ch;
u8 buf1[1024];
if (size == 0 || size >= (int)sizeof(buf1))
return -1;
- /* analyse buffer if smart case */
+ /* analyze buffer if smart case */
if (flags & SEARCH_FLAG_SMARTCASE) {
upper_count = 0;
lower_count = 0;
@@ -5395,6 +5422,7 @@
i = 0;
for (;;) {
+ /* CG: Should bufferize a bit ? */
eb_read(b, offset + i, &ch, 1);
if (flags & SEARCH_FLAG_IGNORECASE)
ch = qe_toupper(ch);
@@ -5404,7 +5432,7 @@
if (i == size) {
/* check end of word */
if (flags & SEARCH_FLAG_WORD) {
- ch = eb_prevc(b, offset + size, NULL);
+ ch = eb_nextc(b, offset + size, NULL);
if (qe_isword(ch))
break;
}
@@ -5466,6 +5494,7 @@
*q++ |= h;
hex_nibble ^= 1;
}
+ /* CG: should handle unihex mode */
} else {
q += unicode_to_charset((char *)q, v, s->b->charset);
}
@@ -5482,8 +5511,8 @@
flags = is->search_flags;
if (s->hex_mode)
flags = 0;
- is->found_offset = eb_search(s->b, search_offset, is->dir, buf, len,
- flags, search_abort_func, NULL);
+ is->found_offset = eb_search(s->b, search_offset, is->dir, flags,
+ buf, len, search_abort_func, NULL);
if (is->found_offset >= 0)
s->offset = is->found_offset + len;
}
@@ -5575,6 +5604,7 @@
case KEY_CTRL('w'):
case KEY_CTRL('y'):
/* emacs compatibility: get word / line */
+ /* CG: should yank into search string */
break;
#endif
/* case / word */
@@ -5604,7 +5634,7 @@
unget_key(ch);
goto the_end;
} else {
- // addch:
+ //addch:
if (is->pos < SEARCH_LENGTH) {
is->search_string[is->pos++] = ch;
}
@@ -5708,9 +5738,9 @@
EditState *s = is->s;
redo:
- is->found_offset = eb_search(s->b, is->found_offset, 1,
+ is->found_offset = eb_search(s->b, is->found_offset, 1, is->flags,
is->search_bytes, is->search_bytes_len,
- is->flags, NULL, NULL);
+ NULL, NULL);
if (is->found_offset < 0) {
query_replace_abort(is);
return;
@@ -5809,9 +5839,8 @@
search_bytes_len = to_bytes(s, search_bytes, sizeof(search_bytes),
search_str);
- found_offset = eb_search(s->b, s->offset, dir,
- search_bytes, search_bytes_len,
- 0, NULL, NULL);
+ found_offset = eb_search(s->b, s->offset, dir, 0,
+ search_bytes, search_bytes_len, NULL, NULL);
if (found_offset >= 0) {
s->offset = found_offset;
do_center_cursor(s);
@@ -5844,6 +5873,7 @@
s->display_invalid = 1;
}
+/* refresh the screen, s1 can be any edit window */
void do_refresh(__unused__ EditState *s1)
{
/* CG: s1 may be NULL */
@@ -5867,10 +5897,8 @@
width = qs->screen->width;
height = qs->screen->height;
- new_status_height = get_line_height(qs->screen,
- QE_STYLE_STATUS);
- new_mode_line_height = get_line_height(qs->screen,
- QE_STYLE_MODE_LINE);
+ new_status_height = get_line_height(qs->screen, QE_STYLE_STATUS);
+ new_mode_line_height = get_line_height(qs->screen, QE_STYLE_MODE_LINE);
content_height = height;
if (!qs->hide_status)
content_height -= new_status_height;
@@ -6004,15 +6032,18 @@
/* left border */
e->x2 = x2;
break;
- } else if (x2 == ex1 && y1 == ey1 && y2 == ey2) {
+ } else
+ if (x2 == ex1 && y1 == ey1 && y2 == ey2) {
/* right border */
e->x1 = x1;
break;
- } else if (y1 == ey2 && x1 == ex1 && x2 == ex2) {
+ } else
+ if (y1 == ey2 && x1 == ex1 && x2 == ex2) {
/* top border */
e->y2 = y2;
break;
- } else if (y2 == ey1 && x1 == ex1 && x2 == ex2) {
+ } else
+ if (y2 == ey1 && x1 == ex1 && x2 == ex2) {
/* bottom border */
e->y1 = y1;
break;
@@ -6548,6 +6579,8 @@
}
}
+/* text mode */
+
static int text_mode_probe(__unused__ ModeProbeData *p)
{
return 10;
@@ -7218,7 +7251,7 @@
initcall = *ptr;
if (initcall == NULL)
break;
- initcall();
+ (*initcall)();
}
}
#else
Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -b -r1.54 -r1.55
--- qe.h 3 Jan 2008 09:51:31 -0000 1.54
+++ qe.h 3 Jan 2008 18:31:25 -0000 1.55
@@ -230,7 +230,8 @@
void css_strtolower(char *buf, int buf_size);
void skip_spaces(const char **pp);
-int strfind(const char *keytable, const char *str, int casefold);
+int strfind(const char *list, const char *s);
+int strcasefind(const char *list, const char *s);
const void *memstr(const void *buf, int size, const char *str);
#define stristart(str, val, ptr) qe_stristart(str, val, ptr)
@@ -1159,10 +1160,10 @@
/* dynamic key binding storage */
typedef struct KeyDef {
- int nb_keys;
struct CmdDef *cmd;
- ModeDef *mode; /* if non NULL, key is only active in this mode */
struct KeyDef *next;
+ ModeDef *mode; /* if non NULL, key is only active in this mode */
+ int nb_keys;
unsigned int keys[1];
} KeyDef;
@@ -1368,9 +1369,7 @@
struct InputMethod *next;
} InputMethod;
-extern InputMethod *input_methods;
-
-//void register_input_method(InputMethod *m);
+void register_input_method(InputMethod *m);
void do_set_input_method(EditState *s, const char *method);
void do_switch_input_method(EditState *s);
void init_input_methods(void);
@@ -1404,7 +1403,6 @@
} CompletionEntry;
void register_completion(const char *name, CompletionFunc completion_func);
-//void vput_status(EditState *s, const char *fmt, va_list ap);
void put_status(EditState *s, const char *fmt, ...) __attr_printf(2,3);
void put_error(EditState *s, const char *fmt, ...) __attr_printf(2,3);
void minibuffer_edit(const char *input, const char *prompt,
@@ -1459,6 +1457,7 @@
void edit_display(QEmacsState *qs);
void edit_invalidate(EditState *s);
void display_mode_line(EditState *s);
+void edit_set_mode(EditState *s, ModeDef *m, ModeSavedData *saved_data);
/* loading files */
void do_exit_qemacs(EditState *s, int argval);
@@ -1494,16 +1493,13 @@
int offset1, int line_num);
void do_char(EditState *s, int key, int argval);
-// bad name!
-// void do_set_mode(EditState *s, const char *mode_name);
-void do_set_mode(EditState *s, ModeDef *m, ModeSavedData *saved_data);
-void do_cmd_set_mode(EditState *s, const char *name);
+void do_set_mode(EditState *s, const char *name);
void text_move_left_right_visual(EditState *s, int dir);
void text_move_word_left_right(EditState *s, int dir);
void text_move_up_down(EditState *s, int dir);
void text_scroll_up_down(EditState *s, int dir);
void text_write_char(EditState *s, int key);
-void do_return(EditState *s);
+void do_return(EditState *s, int move);
void do_backspace(EditState *s, int argval);
void do_delete_char(EditState *s, int argval);
void do_tab(EditState *s, int argval);
@@ -1554,7 +1550,6 @@
void do_center_cursor(EditState *s);
void do_quote(EditState *s, int argval);
void do_insert(EditState *s);
-void do_open_line(EditState *s);
// should take argval
void do_set_mark(EditState *s);
void do_mark_whole_buffer(EditState *s);
@@ -1610,8 +1605,9 @@
void do_load_file_from_path(EditState *s, const char *filename);
void do_set_visited_file_name(EditState *s, const char *filename,
const char *renamefile);
-int eb_search(EditBuffer *b, int offset, int dir, u8 *buf, int size,
- int flags, CSSAbortFunc *abort_func, void *abort_opaque);
+int eb_search(EditBuffer *b, int offset, int dir, int flags,
+ const u8 *buf, int size,
+ CSSAbortFunc *abort_func, void *abort_opaque);
int search_abort_func(void *opaque);
void do_doctor(EditState *s);
void do_delete_other_windows(EditState *s);
Index: qeconfig.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qeconfig.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- qeconfig.h 3 Jan 2008 09:51:31 -0000 1.25
+++ qeconfig.h 3 Jan 2008 18:31:25 -0000 1.26
@@ -53,8 +53,8 @@
CMD_( KEY_CTRL('i'), KEY_NONE, "tabulate", do_tab, ESi, "ui")
//CMD_( KEY_SPC, KEY_NONE, "space", do_space, "*ui")
CMD_( KEY_CTRL('q'), KEY_NONE, "quoted-insert", do_quote, ESi, "*ui")
- CMD_( KEY_CTRL('j'), KEY_RET, "newline", do_return, ES, "*")
- CMD_( KEY_CTRL('o'), KEY_NONE, "open-line", do_open_line, ES, "*")
+ CMDV( KEY_CTRL('j'), KEY_RET, "newline", do_return, ESi, 1, "*v")
+ CMDV( KEY_CTRL('o'), KEY_NONE, "open-line", do_return, ESi, 0, "*v")
/*---------------- Region handling / Kill commands ----------------*/
@@ -236,7 +236,7 @@
CMD0( KEY_NONE, KEY_NONE, "set-trace", do_set_trace)
CMD_( KEY_NONE, KEY_NONE, "cd", do_cd, ESs,
"s{Change default directory: }[file]|file|")
- CMD_( KEY_NONE, KEY_NONE, "set-mode", do_cmd_set_mode, ESs,
+ CMD_( KEY_NONE, KEY_NONE, "set-mode", do_set_mode, ESs,
"s{Set mode: }[mode]")
/* tab & indent */
Index: shell.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/shell.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- shell.c 3 Jan 2008 09:51:32 -0000 1.36
+++ shell.c 3 Jan 2008 18:31:25 -0000 1.37
@@ -1160,7 +1160,7 @@
return;
switch_to_buffer(s, b);
- do_set_mode(s, &shell_mode, NULL);
+ edit_set_mode(s, &shell_mode, NULL);
put_status(s, "Press C-o to toggle between shell/edit mode");
shell_launched = 1;
@@ -1252,7 +1252,7 @@
do_backspace(e, NO_ARG);
break;
case '\r':
- do_return(e);
+ do_return(e, 1);
break;
default:
text_write_char(e, c);
Index: util.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/util.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- util.c 3 Jan 2008 09:51:32 -0000 1.31
+++ util.c 3 Jan 2008 18:31:25 -0000 1.32
@@ -339,7 +339,7 @@
r = extension(filename);
if (*r == '.') {
- return strfind(extlist, r + 1, 1);
+ return strcasefind(extlist, r + 1);
} else {
return 0;
}
@@ -390,20 +390,13 @@
pstrcpy(filename, filename_size, base);
}
-/* find a word in a list using '|' as separator,
- * optionally fold case to lower case.
- */
-int strfind(const char *keytable, const char *str, int casefold)
+#if 0
+/* find a word in a list using '|' as separator */
+int strfind(const char *keytable, const char *str)
{
- char buf[128];
int c, len;
const char *p;
- if (casefold) {
- pstrcpy(buf, sizeof(buf), str);
- str = buf;
- css_strtolower(buf, sizeof(buf));
- }
c = *str;
len = strlen(str);
/* need to special case the empty string */
@@ -424,6 +417,58 @@
}
}
}
+#else
+/* Search for the string s in '|' delimited list of strings */
+int strfind(const char *list, const char *s)
+{
+ const char *p, *q;
+ int c1, c2;
+
+ q = list;
+ if (*s == '\0') {
+ /* special case the empty string: must match || in list */
+ while (*q) {
+ if (q[0] == '|' && q[1] == '|')
+ return 1;
+ q++;
+ }
+ return 0;
+ } else {
+ scan:
+ p = s;
+ for (;;) {
+ c1 = *p++;
+ c2 = *q++;
+ if (c1 == '\0') {
+ if (c2 == '\0' || c2 == '|')
+ return 1;
+ goto skip;
+ }
+ if (c1 != c2) {
+ for (;;) {
+ if (c2 == '|')
+ goto scan;
+
+ if (c2 == '\0')
+ return 0;
+ skip:
+ c2 = *q++;
+ }
+ }
+ }
+ }
+}
+#endif
+
+/* find a word in a list using '|' as separator, fold case to lower case. */
+int strcasefind(const char *list, const char *s)
+{
+ char buf[128];
+
+ pstrcpy(buf, sizeof(buf), s);
+ css_strtolower(buf, sizeof(buf));
+ return strfind(list, buf);
+}
const void *memstr(const void *buf, int size, const char *str)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs bufed.c buffer.c charset.c clang.c dired...,
Charlie Gordon <=