[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs hex.c qe.h unihex.c variables.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs hex.c qe.h unihex.c variables.c |
Date: |
Thu, 13 Aug 2015 23:27:00 +0000 |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 15/08/13 23:27:00
Modified files:
. : hex.c qe.h unihex.c variables.c
Log message:
hex-mode: some improvements
- added probe function for binary mode so it gets selected when cycling
modes with next-mode (bound to M-m)
- renamed w->disp_width as dump_width and make it a window variable
- compute default dump-width more accurately for dired-mode
- dump-width can be controlled with C-left and C-right in
hex, unihex and binary modes
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/hex.c?cvsroot=qemacs&r1=1.43&r2=1.44
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.192&r2=1.193
http://cvs.savannah.gnu.org/viewcvs/qemacs/unihex.c?cvsroot=qemacs&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/qemacs/variables.c?cvsroot=qemacs&r1=1.17&r2=1.18
Patches:
Index: hex.c
===================================================================
RCS file: /sources/qemacs/qemacs/hex.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- hex.c 1 Jun 2014 13:54:58 -0000 1.43
+++ hex.c 13 Aug 2015 23:26:59 -0000 1.44
@@ -41,7 +41,7 @@
static int hex_backward_offset(EditState *s, int offset)
{
- return align(offset, s->disp_width);
+ return align(offset, s->dump_width);
}
static int hex_display(EditState *s, DisplayState *ds, int offset)
@@ -57,14 +57,14 @@
ateof = 0;
len = s->b->total_size - offset;
- if (len > s->disp_width)
- len = s->disp_width;
+ if (len > s->dump_width)
+ len = s->dump_width;
if (s->mode == &hex_mode) {
ds->style = HEX_STYLE_DUMP;
- for (j = 0; j < s->disp_width; j++) {
+ for (j = 0; j < s->dump_width; j++) {
display_char(ds, -1, -1, ' ');
offset1 = offset + j;
offset2 = offset1 + 1;
@@ -91,7 +91,7 @@
display_char(ds, -1, -1, ' ');
ateof = 0;
- for (j = 0; j < s->disp_width; j++) {
+ for (j = 0; j < s->dump_width; j++) {
offset1 = offset + j;
offset2 = offset1 + 1;
if (j < len) {
@@ -108,7 +108,7 @@
}
display_eol(ds, -1, -1);
- if (len >= s->disp_width)
+ if (len >= s->dump_width)
return offset + len;
else
return -1;
@@ -117,7 +117,7 @@
static void do_set_width(EditState *s, int w)
{
if (w >= 1) {
- s->disp_width = w;
+ s->dump_width = w;
s->offset_top = s->mode->text_backward_offset(s, s->offset_top);
}
}
@@ -125,7 +125,7 @@
static void do_incr_width(EditState *s, int incr)
{
int w;
- w = s->disp_width + incr;
+ w = s->dump_width + incr;
if (w >= 1)
do_set_width(s, w);
}
@@ -166,11 +166,15 @@
num_width = glyph_width(s->screen, font, '0');
release_font(s->screen, font);
- s->disp_width = (s->screen->width / num_width) - 10;
+ s->dump_width = s->screen->width / num_width;
+ if (s->b->flags & BF_PREVIEW)
+ s->dump_width = s->dump_width * 4 / 5;
+
+ s->dump_width -= 10;
/* align on 16 byte boundary */
- s->disp_width &= ~15;
- if (s->disp_width < 16)
- s->disp_width = 16;
+ s->dump_width &= ~15;
+ if (s->dump_width < 16)
+ s->dump_width = 16;
s->insert = 0;
s->hex_mode = 0;
s->wrap = WRAP_TRUNCATE;
@@ -181,7 +185,7 @@
static int hex_mode_init(EditState *s, EditBuffer *b, int flags)
{
if (s) {
- s->disp_width = 16;
+ s->dump_width = 16;
s->hex_mode = 1;
s->unihex_mode = 0;
s->hex_nibble = 0;
@@ -216,12 +220,12 @@
static void hex_move_bol(EditState *s)
{
- s->offset = align(s->offset, s->disp_width);
+ s->offset = align(s->offset, s->dump_width);
}
static void hex_move_eol(EditState *s)
{
- s->offset = align(s->offset, s->disp_width) + s->disp_width - 1;
+ s->offset = align(s->offset, s->dump_width) + s->dump_width - 1;
if (s->offset > s->b->total_size)
s->offset = s->b->total_size;
}
@@ -238,7 +242,7 @@
static void hex_move_up_down(EditState *s, int dir)
{
- s->offset += dir * s->disp_width;
+ s->offset += dir * s->dump_width;
if (s->offset < 0)
s->offset = 0;
else
@@ -318,9 +322,14 @@
buf_printf(out, "--%d%%", compute_percent(s->offset, s->b->total_size));
}
+static int binary_mode_probe(ModeDef *mode, ModeProbeData *p)
+{
+ return 5;
+}
+
static ModeDef binary_mode = {
.name = "binary",
- .mode_probe = NULL,
+ .mode_probe = binary_mode_probe,
.mode_init = binary_mode_init,
.text_display = hex_display,
.text_backward_offset = hex_backward_offset,
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.192
retrieving revision 1.193
diff -u -b -r1.192 -r1.193
--- qe.h 11 Aug 2015 22:15:38 -0000 1.192
+++ qe.h 13 Aug 2015 23:26:59 -0000 1.193
@@ -1129,7 +1129,7 @@
int y_disp; /* virtual position of the displayed text */
int x_disp[2]; /* position for LTR and RTL text resp. */
int minibuf; /* true if single line editing */
- int disp_width; /* width in binary, hex and unihex modes */
+ int dump_width; /* width in binary, hex and unihex modes */
int hex_mode; /* true if we are currently editing hexa */
int unihex_mode; /* true if unihex editing (width of hex char dump) */
int hex_nibble; /* current hexa nibble */
Index: unihex.c
===================================================================
RCS file: /sources/qemacs/qemacs/unihex.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- unihex.c 1 Jun 2014 13:54:59 -0000 1.28
+++ unihex.c 13 Aug 2015 23:26:59 -0000 1.29
@@ -44,7 +44,7 @@
s->unihex_mode = snprintf(NULL, 0, "%x", maxc);
- s->disp_width = 32 / s->unihex_mode;
+ s->dump_width = 32 / s->unihex_mode;
s->hex_mode = 1;
s->hex_nibble = 0;
s->insert = 0;
@@ -69,13 +69,13 @@
/* CG: beware: offset may fall inside a character */
pos = eb_get_char_offset(s->b, offset);
- pos = align(pos, s->disp_width);
+ pos = align(pos, s->dump_width);
return eb_goto_char(s->b, pos);
}
static int unihex_display(EditState *s, DisplayState *ds, int offset)
{
- int j, len, ateof, disp_width;
+ int j, len, ateof, dump_width;
int offset1, offset2;
unsigned int b;
/* CG: array size is incorrect, should be smaller */
@@ -90,10 +90,10 @@
//display_printf(ds, -1, -1, "%08x ", charpos);
//display_printf(ds, -1, -1, "%08x %08x ", charpos, offset);
- disp_width = min(LINE_MAX_SIZE - 1, s->disp_width);
+ dump_width = min(LINE_MAX_SIZE - 1, s->dump_width);
ateof = 0;
len = 0;
- for (j = 0; j < disp_width && offset < s->b->total_size; j++) {
+ for (j = 0; j < dump_width && offset < s->b->total_size; j++) {
pos[len] = offset;
buf[len] = eb_nextc(s->b, offset, &offset);
len++;
@@ -102,7 +102,7 @@
ds->style = UNIHEX_STYLE_DUMP;
- for (j = 0; j < disp_width; j++) {
+ for (j = 0; j < dump_width; j++) {
display_char(ds, -1, -1, ' ');
offset1 = pos[j];
offset2 = pos[j + 1];
@@ -132,7 +132,7 @@
display_char(ds, -1, -1, ' ');
ateof = 0;
- for (j = 0; j < disp_width; j++) {
+ for (j = 0; j < dump_width; j++) {
offset1 = pos[j];
offset2 = pos[j + 1];
if (j < len) {
@@ -156,7 +156,7 @@
}
display_eol(ds, -1, -1);
- if (len >= disp_width)
+ if (len >= dump_width)
return offset;
else
return -1;
@@ -167,7 +167,7 @@
int pos;
pos = eb_get_char_offset(s->b, s->offset);
- pos = align(pos, s->disp_width);
+ pos = align(pos, s->dump_width);
s->offset = eb_goto_char(s->b, pos);
}
@@ -178,7 +178,7 @@
pos = eb_get_char_offset(s->b, s->offset);
/* CG: should include the last character! */
- pos = align(pos, s->disp_width) + s->disp_width - 1;
+ pos = align(pos, s->dump_width) + s->dump_width - 1;
s->offset = eb_goto_char(s->b, pos);
}
@@ -198,7 +198,7 @@
pos = eb_get_char_offset(s->b, s->offset);
- pos += dir * s->disp_width;
+ pos += dir * s->dump_width;
s->offset = eb_goto_char(s->b, pos);
}
Index: variables.c
===================================================================
RCS file: /sources/qemacs/qemacs/variables.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- variables.c 13 Aug 2015 23:00:26 -0000 1.17
+++ variables.c 13 Aug 2015 23:27:00 -0000 1.18
@@ -70,12 +70,13 @@
W_VAR( "window-left", xleft, VAR_NUMBER, VAR_RW )
W_VAR( "window-top", ytop, VAR_NUMBER, VAR_RW )
W_VAR( "window-prompt", prompt, VAR_STRING, VAR_RW )
+ W_VAR( "dump-width", dump_width, VAR_NUMBER, VAR_RW )
M_VAR( "mode-name", name, VAR_STRING, VAR_RO )
M_VAR( "auto-indent", auto_indent, VAR_NUMBER, VAR_RW )
/* more buffer fields: modified, readonly, binary, charset */
- /* more window fields: mode_line, disp_width, color, input_method...
+ /* more window fields: mode_line, color, input_method...
*/
//G_VAR( "text-mode-line", text_mode.mode_line, VAR_STRING, VAR_RW )
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs hex.c qe.h unihex.c variables.c,
Charlie Gordon <=