se

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

normal_config.def.c (9816B)


      1 #include "config.h"
      2 
      3 ////////////////////////////////////////
      4 // apperance
      5 //
      6 
      7 // font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
      8 //char *fontconfig = "Liberation Mono:pixelsize=16:antialias=true:autohint=true";
      9 char *fontconfig = "Iosevka:pixelsize=16:antialias=true:autohint=true";
     10 
     11 // pixels of border around the window
     12 int border_px = 2;
     13 
     14 // default size of the editor
     15 unsigned int default_cols = 80;
     16 unsigned int default_rows = 24;
     17 
     18 // Kerning / character bounding-box multipliers
     19 float cw_scale = 1.0;
     20 float ch_scale = 1.0;
     21 
     22 int wrap_buffer = 0;
     23 
     24 // spaces per tab (tabs will self align)
     25 unsigned int tabspaces = 8;
     26 
     27 // Default shape of cursor
     28 // 2: Block ("█")
     29 // 4: Underline ("_")
     30 // 6: Bar ("|")
     31 unsigned int cursor_shape = 2;
     32 
     33 // thickness of underline and bar cursors
     34 unsigned int cursor_thickness = 2;
     35 
     36 ///////////////////////////////////////////
     37 // color scheme
     38 // the syntax highlighting is applied in one pass,
     39 // so you can't have nested syntax highlighting
     40 //
     41 
     42 #include "plugins/color_schemes/gruvbox.h"
     43 
     44 // disable coloring functions for the syntax schemes below
     45 #undef function_color
     46 
     47 #include "plugins/syntax/c.h"
     48 
     49 const struct syntax_scheme syntax_schemes[] = {
     50 	{".c", c_word_seperators, c_syntax, LEN(c_syntax)},
     51 	{".h", c_word_seperators, c_syntax, LEN(c_syntax)},
     52 	{0},
     53 };
     54 
     55 /////////////////////////////////////////
     56 // Shortcuts
     57 //
     58 
     59 #include "plugins/shortcuts.h"
     60 #include "plugins/default_shortcuts.h"
     61 
     62 #define MODKEY Mod1Mask
     63 #define CtrlShift (ControlMask|ShiftMask)
     64 
     65 shortcuts = {
     66 //    mask                  keysym          function        argument
     67 	{ 0,                    XK_Right,       cursor_move_x_relative,       {.i = +1} },
     68 	{ 0,                    XK_Left,        cursor_move_x_relative,       {.i = -1} },
     69 	{ 0,                    XK_Down,        cursor_move_y_relative,       {.i = +1} },
     70 	{ 0,                    XK_Up,          cursor_move_y_relative,       {.i = -1} },
     71 	{ ControlMask,          XK_Right,       window_change,                {.i = MOVE_RIGHT} },
     72 	{ ControlMask,          XK_Left,        window_change,                {.i = MOVE_LEFT}  },
     73 	{ ControlMask,          XK_Down,        window_change,                {.i = MOVE_DOWN}  },
     74 	{ ControlMask,          XK_Up,          window_change,                {.i = MOVE_UP}    },
     75 	{ CtrlShift,            XK_Right,       window_resize,                {.i = MOVE_RIGHT} },
     76 	{ CtrlShift,            XK_Left,        window_resize,                {.i = MOVE_LEFT}  },
     77 	{ CtrlShift,            XK_Down,        window_resize,                {.i = MOVE_DOWN}  },
     78 	{ CtrlShift,            XK_Up,          window_resize,                {.i = MOVE_UP}    },
     79 	{ ControlMask,          XK_Tab,         swap_to_next_file_buffer,     {0}       },
     80 	{ ControlMask,          XK_m,           toggle_selection,             {0}       },
     81 	{ ControlMask,          XK_g,           move_cursor_to_offset,        {0}       },
     82 	{ CtrlShift,            XK_G,           move_cursor_to_end_of_buffer, {0}       },
     83 	{ ControlMask,          XK_period,      open_file_browser,            {0}       },
     84 	{ CtrlShift,            XK_D,           buffer_kill,                  {0}       },
     85 	{ ControlMask,          XK_l,           window_split,   {.i = WINDOW_HORISONTAL}},
     86 	{ ControlMask,          XK_k,           window_split,   {.i = WINDOW_VERTICAL}  },
     87 	{ ControlMask,          XK_d,           window_delete,  {0}       },
     88 	{ ControlMask,          XK_z,           undo,           {0}       },
     89 	{ CtrlShift,            XK_Z,           redo,           {0}       },
     90 	{ ControlMask,          XK_s,           save_buffer,    {0}       },
     91 	{ ControlMask,          XK_f,           search,         {0}       },
     92 	{ CtrlShift,            XK_F,           search_keyword_in_buffers,{0},},
     93 	{ ControlMask,          XK_space,       search_for_buffer,{0},    },
     94 	{ ControlMask,          XK_n,           search_next,    {0}       },
     95 	{ CtrlShift,            XK_N,           search_previous,{0}       },
     96 	{ ControlMask,          XK_c,           clipboard_copy, {0}       },
     97 	{ ControlMask,          XK_v,           clipboard_paste,{0}       },
     98 	{ CtrlShift,            XK_Prior,       zoom,           {.f = +1} },
     99 	{ CtrlShift,            XK_Next,        zoom,           {.f = -1} },
    100 	{ CtrlShift,            XK_Home,        zoomreset,      {.f =  0} },
    101 	{ CtrlShift,            XK_Num_Lock,    numlock,        {.i =  0} },
    102 };
    103 
    104 /////////////////////////////////////////////////
    105 // callbacks
    106 //
    107 
    108 static void cursor_callback(struct window_buffer* buf, enum cursor_reason callback_reason);
    109 static void keep_cursor_col(struct window_buffer* buf, enum cursor_reason callback_reason);
    110 static void move_selection(struct window_buffer* buf, enum cursor_reason callback_reason);
    111 static int keypress_actions(KeySym keysym, int modkey);
    112 static void string_insert_callback(const char* buf, int buflen);
    113 #include "plugins/default_status_bar.h"
    114 
    115 void(*cursor_movement_callback)(struct window_buffer*, enum cursor_reason) = cursor_callback;
    116 void(*buffer_contents_updated)(struct file_buffer*, int, enum buffer_content_reason) = buffer_add_to_undo;
    117 int(*keypress_callback)(KeySym, int) = keypress_actions;
    118 void(*string_input_callback)(const char*, int) = string_insert_callback;
    119 void(*draw_callback)(void) = NULL;
    120 void(*startup_callback)(void) = NULL;
    121 void(*buffer_written_to_screen_callback)(struct window_buffer* buf, int offset_start, int offset_end,  int minx, int miny, int maxx, int maxy) = NULL;
    122 char*(*new_line_draw)(struct window_buffer* buf, int y, int lines_left, int minx, int maxx, Glyph* attr) = NULL;
    123 void(*buffer_written_to_file_callback)(struct file_buffer* fb) = NULL;
    124 int(*write_status_bar)(struct window_buffer* buf, int minx, int maxx, int cx, int cy, char line[LINE_MAX_LEN], Glyph* g) = default_status_bar;
    125 
    126 void
    127 keep_cursor_col(struct window_buffer* buf, enum cursor_reason callback_reason)
    128 {
    129 	if (callback_reason == CURSOR_COMMAND_MOVEMENT || callback_reason == CURSOR_RIGHT_LEFT_MOVEMENT) {
    130 		int y;
    131 		buffer_offset_to_xy(buf, buf->cursor_offset, -1, &buf->cursor_col, &y);
    132 	}
    133 }
    134 
    135 void move_selection(struct window_buffer* buf, enum cursor_reason callback_reason)
    136 {
    137 	struct file_buffer* fb = get_file_buffer(buf);
    138 	if (fb->mode & BUFFER_SELECTION_ON) {
    139 		fb->s2o = buf->cursor_offset;
    140 	}
    141 }
    142 
    143 void
    144 cursor_callback(struct window_buffer* buf, enum cursor_reason callback_reason)
    145 {
    146 	keep_cursor_col(buf, callback_reason);
    147 	move_selection(buf, callback_reason);
    148 
    149 	//writef_to_status_bar("moved to: %d | reason: %d\n", buf->cursor_offset, callback_reason);
    150 }
    151 
    152 int
    153 keypress_actions(KeySym keysym, int modkey)
    154 {
    155 	check_shortcuts(keysym, modkey);
    156 
    157 	// default actions
    158 
    159 	int offset = focused_window->cursor_offset;
    160 	struct file_buffer* fb = get_file_buffer(focused_window);
    161 
    162 	switch (keysym) {
    163 		int move;
    164 	case XK_BackSpace:
    165 		if (delete_selection(fb)) return 1;
    166 		if (offset <= 0) return 1;
    167 
    168 		if (fb->contents[offset-1] == '\n')
    169 			buffer_move_lines(focused_window, -1, CURSOR_COMMAND_MOVEMENT);
    170 		 else
    171 			buffer_move_on_line(focused_window, -1, CURSOR_COMMAND_MOVEMENT);
    172 
    173 		offset = focused_window->cursor_offset;
    174 
    175 		goto skip_delete_remove_selection;
    176 	case XK_Delete:
    177 
    178 		if (delete_selection(fb)) return 1;
    179 skip_delete_remove_selection:
    180 
    181 		move = buffer_remove(fb, offset, 1, 0, 0);
    182 		window_move_all_cursors_on_same_buf(&root_node, focused_node, focused_window->buffer_index, offset,
    183 											buffer_move_offset_relative, -move, CURSOR_COMMAND_MOVEMENT);
    184 		return 1;
    185 	case XK_Escape:
    186 		fb->mode &= ~BUFFER_SEARCH_BLOCKING_MASK;
    187 		fb->mode &= ~BUFFER_SEARCH_NON_BLOCKING;
    188 		fb->mode &= ~BUFFER_SEARCH_NON_BLOCKING_BACKWARDS;
    189 		fb->mode &= ~BUFFER_SEARCH_BLOCKING_BACKWARDS;
    190 		writef_to_status_bar("");
    191 		return 1;
    192 	case XK_Return:
    193 		delete_selection(fb);
    194 
    195 		buffer_insert(fb, "\n", 1, offset, 0);
    196 		window_move_all_cursors_on_same_buf(&root_node, NULL, focused_window->buffer_index, offset,
    197 											buffer_move_offset_relative, 1, CURSOR_COMMAND_MOVEMENT);
    198 		window_move_all_yscrolls(&root_node, focused_node, focused_window->buffer_index, offset, 1);
    199 		return 1;
    200 	case XK_Home: {
    201 		int new_offset = buffer_seek_char_backwards(fb, offset, '\n');
    202 		if (new_offset < 0)
    203 			new_offset = 0;
    204 		buffer_move_to_offset(focused_window, new_offset, CURSOR_COMMAND_MOVEMENT);
    205 		return 1;
    206 	}
    207 	case XK_End: {
    208 		int new_offset = buffer_seek_char(fb, offset, '\n');
    209 		if (new_offset < 0)
    210 			new_offset = fb->len-1;
    211 		buffer_move_to_offset(focused_window, new_offset, CURSOR_COMMAND_MOVEMENT);
    212 		return 1;
    213 	}
    214 	case XK_Page_Down:
    215 		buffer_move_lines(focused_window, (focused_node->maxy - focused_node->miny) / 2, 0);
    216 		buffer_move_to_x(focused_window, focused_window->cursor_col, CURSOR_UP_DOWN_MOVEMENT);
    217 		focused_window->y_scroll += (focused_node->maxy - focused_node->miny) / 2;
    218 		return 1;
    219 	case XK_Page_Up:
    220 		buffer_move_lines(focused_window, -((focused_node->maxy - focused_node->miny) / 2), 0);
    221 		buffer_move_to_x(focused_window, focused_window->cursor_col, CURSOR_UP_DOWN_MOVEMENT);
    222 		focused_window->y_scroll -= (focused_node->maxy - focused_node->miny) / 2;
    223 		return 1;
    224 	case XK_Tab:
    225 		buffer_insert(fb, "\t", 1, offset, 0);
    226 		window_move_all_cursors_on_same_buf(&root_node, NULL, focused_window->buffer_index, offset,
    227 											buffer_move_on_line, 1, CURSOR_COMMAND_MOVEMENT);
    228 		return 1;
    229 	}
    230 	return 0;
    231 }
    232 
    233 void string_insert_callback(const char* buf, int buflen)
    234 {
    235 	struct file_buffer* fb = get_file_buffer(focused_window);
    236 
    237 	if (buf[0] >= 32 || buflen > 1) {
    238 		delete_selection(fb);
    239 		buffer_insert(fb, buf, buflen, focused_window->cursor_offset, 0);
    240 		window_move_all_cursors_on_same_buf(&root_node, NULL, focused_window->buffer_index, focused_window->cursor_offset,
    241 											buffer_move_offset_relative, buflen, CURSOR_COMMAND_MOVEMENT);
    242 	} else {
    243 		writef_to_status_bar("unhandled control character 0x%x\n", buf[0]);
    244 	}
    245 }