2004-05-29 10:17:37 +00:00
|
|
|
/*
|
|
|
|
|
* List mode for QEmacs.
|
2007-12-03 16:10:38 +00:00
|
|
|
*
|
2004-05-29 10:17:37 +00:00
|
|
|
* Copyright (c) 2001, 2002 Fabrice Bellard.
|
2013-12-03 17:36:15 +00:00
|
|
|
* Copyright (c) 2002-2013 Charlie Gordon.
|
2004-05-29 10:17:37 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2007-12-03 16:10:38 +00:00
|
|
|
|
2004-05-29 10:17:37 +00:00
|
|
|
#include "qe.h"
|
|
|
|
|
|
2013-12-03 17:36:15 +00:00
|
|
|
ModeDef list_mode;
|
|
|
|
|
|
2007-12-15 07:31:38 +00:00
|
|
|
static int list_get_colorized_line(EditState *s,
|
|
|
|
|
unsigned int *buf, int buf_size,
|
2008-01-09 13:41:40 +00:00
|
|
|
int *offsetp, __unused__ int line_num)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
|
|
|
|
QEmacsState *qs = s->qe_state;
|
2008-01-09 13:41:40 +00:00
|
|
|
int offset, len;
|
2004-05-29 10:17:37 +00:00
|
|
|
|
2008-01-09 13:41:40 +00:00
|
|
|
offset = *offsetp;
|
|
|
|
|
len = eb_get_line(s->b, buf, buf_size, offsetp);
|
2004-05-29 10:17:37 +00:00
|
|
|
|
|
|
|
|
if (((qs->active_window == s) || s->force_highlight) &&
|
2008-01-09 13:41:40 +00:00
|
|
|
s->offset >= offset && s->offset < *offsetp)
|
|
|
|
|
{
|
2004-05-29 10:17:37 +00:00
|
|
|
/* highlight the line if the cursor is inside */
|
simplified set_color API, made in inline
improved command parsing, refined argval handling, pass as optional arg
pass command arguments as an array of unions
use correct type in command dispatcher (upto 2 arguments)
merged do_goto_byte, do_goto_line, do_goto_char, extend syntax
fixed kill commands: kills are appended/prepended to kill buffer
added append_next_kill command
added do_kill_line (split from do_kill_region)
added do_kill_word (removed do_delete_word)
added do_kill_paragraph
pass argval to do_backspace and do_delete_char, fix kill behaviour
fixed kill-ring initial state bug
fixed do_yank: set mark and this_cmd_func
fixed do_yank_pop: test last_cmd_func, use eb_delete instead of do_undo
fixed do_yank_pop kill-ring bug
added clamp(int x, int min, int max);
added qs->this_cmd_func so commands can override qs->last_cmd_func
allow KEY_ESC + extended key as command binding
added do_c_forward_block, needs rewrite using colorization code
added do_c_kill_block
added insert-char command (argval repeats instead of forcing char value)
renamed delete-word to kill-word
renamed backward-delete-word to backward-kill-word
added kill-beginning-of-line
2007-12-12 02:51:05 +00:00
|
|
|
set_color(buf, buf + len, QE_STYLE_HIGHLIGHT);
|
2007-12-15 07:31:38 +00:00
|
|
|
} else
|
|
|
|
|
if (buf[0] == '*') {
|
2004-05-29 10:17:37 +00:00
|
|
|
/* selection */
|
simplified set_color API, made in inline
improved command parsing, refined argval handling, pass as optional arg
pass command arguments as an array of unions
use correct type in command dispatcher (upto 2 arguments)
merged do_goto_byte, do_goto_line, do_goto_char, extend syntax
fixed kill commands: kills are appended/prepended to kill buffer
added append_next_kill command
added do_kill_line (split from do_kill_region)
added do_kill_word (removed do_delete_word)
added do_kill_paragraph
pass argval to do_backspace and do_delete_char, fix kill behaviour
fixed kill-ring initial state bug
fixed do_yank: set mark and this_cmd_func
fixed do_yank_pop: test last_cmd_func, use eb_delete instead of do_undo
fixed do_yank_pop kill-ring bug
added clamp(int x, int min, int max);
added qs->this_cmd_func so commands can override qs->last_cmd_func
allow KEY_ESC + extended key as command binding
added do_c_forward_block, needs rewrite using colorization code
added do_c_kill_block
added insert-char command (argval repeats instead of forcing char value)
renamed delete-word to kill-word
renamed backward-delete-word to backward-kill-word
added kill-beginning-of-line
2007-12-12 02:51:05 +00:00
|
|
|
set_color(buf, buf + len, QE_STYLE_SELECTION);
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get current position (index) in list */
|
|
|
|
|
int list_get_pos(EditState *s)
|
|
|
|
|
{
|
|
|
|
|
int line, col;
|
|
|
|
|
eb_get_pos(s->b, &line, &col, s->offset);
|
|
|
|
|
return line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get current offset of the line in list */
|
|
|
|
|
int list_get_offset(EditState *s)
|
|
|
|
|
{
|
|
|
|
|
int line, col;
|
|
|
|
|
eb_get_pos(s->b, &line, &col, s->offset);
|
|
|
|
|
return eb_goto_pos(s->b, line, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void list_toggle_selection(EditState *s)
|
|
|
|
|
{
|
|
|
|
|
int offset;
|
|
|
|
|
unsigned char ch;
|
|
|
|
|
|
|
|
|
|
offset = list_get_offset(s);
|
2008-01-03 09:51:29 +00:00
|
|
|
|
2004-05-29 10:17:37 +00:00
|
|
|
eb_read(s->b, offset , &ch, 1);
|
|
|
|
|
if (ch == ' ')
|
|
|
|
|
ch = '*';
|
|
|
|
|
else
|
|
|
|
|
ch = ' ';
|
|
|
|
|
eb_write(s->b, offset , &ch, 1);
|
|
|
|
|
|
|
|
|
|
text_move_up_down(s, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-31 19:34:00 +00:00
|
|
|
static int list_mode_init(EditState *s, __unused__ ModeSavedData *saved_data)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2014-01-15 15:54:27 +00:00
|
|
|
text_mode_init(s, saved_data);
|
|
|
|
|
|
2004-05-29 10:17:37 +00:00
|
|
|
s->wrap = WRAP_TRUNCATE;
|
2008-03-29 18:06:41 +00:00
|
|
|
s->get_colorized_line = list_get_colorized_line;
|
2004-05-29 10:17:37 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int list_init(void)
|
|
|
|
|
{
|
|
|
|
|
memcpy(&list_mode, &text_mode, sizeof(ModeDef));
|
2008-01-07 16:25:22 +00:00
|
|
|
list_mode.name = "list";
|
2004-05-29 10:17:37 +00:00
|
|
|
list_mode.mode_probe = NULL;
|
|
|
|
|
list_mode.mode_init = list_mode_init;
|
|
|
|
|
list_mode.mode_flags = MODEF_NOCMD;
|
|
|
|
|
|
|
|
|
|
qe_register_mode(&list_mode);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qe_module_init(list_init);
|