[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs buffer.c qe.c qe.h qeconfig.h
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs buffer.c qe.c qe.h qeconfig.h |
Date: |
Fri, 21 Dec 2007 22:34:32 +0000 |
CVSROOT: /cvsroot/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 07/12/21 22:34:32
Modified files:
. : buffer.c qe.c qe.h qeconfig.h
Log message:
fixed eb_replace API
added capitalize-word (M-c) and capitalize-region (M-C-c)
fixed eb_changecase and added support for capitalization
simplified do_changecase_word and do_changecase_region
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.50&r2=1.51
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/qemacs/qeconfig.h?cvsroot=qemacs&r1=1.20&r2=1.21
Patches:
Index: buffer.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/buffer.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- buffer.c 21 Dec 2007 12:30:55 -0000 1.24
+++ buffer.c 21 Dec 2007 22:34:31 -0000 1.25
@@ -1194,7 +1194,8 @@
}
/* replace 'size' bytes at offset 'offset' with 'size1' bytes from 'buf' */
-void eb_replace(EditBuffer *b, int offset, int size, const u8 *buf, int size1)
+void eb_replace(EditBuffer *b, int offset, int size,
+ const void *buf, int size1)
{
/* CG: behaviour is not exactly identical: mark, point and other
* callback based offsets will be updated differently. should
Index: qe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -b -r1.50 -r1.51
--- qe.c 21 Dec 2007 14:27:11 -0000 1.50
+++ qe.c 21 Dec 2007 22:34:31 -0000 1.51
@@ -638,67 +638,64 @@
}
}
-/* upper / lower case functions (XXX: use generic unicode
- function). Return next offset */
-static int eb_changecase(EditBuffer *b, int offset, int up)
+/* Upper / lower / capital case functions. Update offset, return isword */
+/* arg: -1=lower-case, +1=upper-case, +2=capital-case */
+/* (XXX: use generic unicode function). */
+static int eb_changecase(EditBuffer *b, int *offsetp, int arg)
{
- int offset1, ch, ch1, len;
+ int offset0, ch, ch1, len;
char buf[MAX_CHAR_BYTES];
- ch = eb_nextc(b, offset, &offset1);
- if (up)
+ offset0 = *offsetp;
+ ch = eb_nextc(b, offset0, offsetp);
+ if (!qe_isword(ch))
+ return 0;
+
+ if (arg > 0)
ch1 = qe_toupper(ch);
else
ch1 = qe_tolower(ch);
- if (ch == ch1) {
- return offset1;
- } else {
- len = unicode_to_charset(buf, ch, b->charset);
- if (len == (offset1 - offset)) {
- eb_write(b, offset, buf, len);
- } else {
- eb_delete(b, offset, offset1 - offset);
- eb_insert(b, offset, buf, len);
- }
- return offset + len;
+ if (ch != ch1) {
+ len = unicode_to_charset(buf, ch1, b->charset);
+ eb_replace(b, offset0, *offsetp - offset0, buf, len);
}
+ return 1;
}
-void do_changecase_word(EditState *s, int up)
+void do_changecase_word(EditState *s, int arg)
{
- int c;
+ int offset;
word_right(s, 1);
- for (;;) {
- if (s->offset >= s->b->total_size)
+ for (offset = s->offset;;) {
+ if (offset >= s->b->total_size)
break;
- c = eb_nextc(s->b, s->offset, NULL);
- if (!qe_isword(c))
+ if (!eb_changecase(s->b, &offset, arg))
break;
- s->offset = eb_changecase(s->b, s->offset, up);
+ s->offset = offset;
+ if (arg == 2)
+ arg = -2;
}
}
-void do_changecase_region(EditState *s, int up)
+void do_changecase_region(EditState *s, int arg)
{
int offset;
/* WARNING: during case change, the region offsets can change, so
it is not so simple ! */
- if (s->offset > s->b->mark)
- offset = s->b->mark;
- else
- offset = s->offset;
+ offset = min(s->offset, s->b->mark);
for (;;) {
- if (s->offset > s->b->mark) {
- if (offset >= s->offset)
+ if (offset >= max(s->offset, s->b->mark))
break;
+ if (eb_changecase(s->b, &offset, arg)) {
+ if (arg == 2)
+ arg = -arg;
} else {
- if (offset >= s->b->mark)
- break;
+ if (arg == -2)
+ arg = -arg;
}
- offset = eb_changecase(s->b, offset, up);
}
}
Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- qe.h 21 Dec 2007 14:27:11 -0000 1.45
+++ qe.h 21 Dec 2007 22:34:32 -0000 1.46
@@ -735,7 +735,8 @@
int size);
void eb_insert(EditBuffer *b, int offset, const void *buf, int size);
void eb_delete(EditBuffer *b, int offset, int size);
-void eb_replace(EditBuffer *b, int offset, int size, const u8 *buf, int size1);
+void eb_replace(EditBuffer *b, int offset, int size,
+ const void *buf, int size1);
void log_reset(EditBuffer *b);
EditBuffer *eb_new(const char *name, int flags);
EditBuffer *eb_scratch(const char *name);
Index: qeconfig.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qeconfig.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- qeconfig.h 21 Dec 2007 10:28:14 -0000 1.20
+++ qeconfig.h 21 Dec 2007 22:34:32 -0000 1.21
@@ -118,12 +118,15 @@
CMD_( KEY_META('q'), KEY_NONE, "fill-paragraph", do_fill_paragraph, "*")
CMDV( KEY_NONE, KEY_NONE, "kill-paragraph", do_kill_paragraph, 1, "*v")
- CMDV( KEY_META('l'), KEY_NONE, "downcase-word", do_changecase_word, 0,
"*v")
+ CMDV( KEY_META('c'), KEY_NONE, "capitalize-word", do_changecase_word, 2,
"*v")
+ CMDV( KEY_META('l'), KEY_NONE, "downcase-word", do_changecase_word, -1,
"*v")
CMDV( KEY_META('u'), KEY_NONE, "upcase-word", do_changecase_word, 1, "*v")
- CMDV( KEY_CTRLX(KEY_CTRL('l')), KEY_NONE, "downcase-region",
- do_changecase_region, 0, "*v")
- CMDV( KEY_CTRLX(KEY_CTRL('u')), KEY_NONE, "upcase-region",
- do_changecase_region, 1, "*v")
+ CMDV( KEY_META(KEY_CTRL('c')), KEY_NONE,
+ "capitalize-region", do_changecase_region, 2, "*v")
+ CMDV( KEY_CTRLX(KEY_CTRL('l')), KEY_META(KEY_CTRL('l')),
+ "downcase-region", do_changecase_region, -1, "*v")
+ CMDV( KEY_CTRLX(KEY_CTRL('u')), KEY_META(KEY_CTRL('u')),
+ "upcase-region", do_changecase_region, 1, "*v")
/*---------------- Command handling ----------------*/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs buffer.c qe.c qe.h qeconfig.h,
Charlie Gordon <=