Update Makefile and rename list function.
[eco.git] / cmd.c
blob02b53d5ae432973a738c28ccc3b3b1a2630a8c35
1 /*
2 * Copyright (C) 2008 Diego Hernan Borghetti.
3 * Eco
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
10 #include "term.h"
11 #include "screen.h"
12 #include "buffer.h"
13 #include "view.h"
14 #include "eco.h"
15 #include "file.h"
16 #include "status.h"
17 #include "cmd.h"
18 #include "kill.h"
19 #include "update.h"
22 void e_cmd_cr(E_Eco *ec)
24 if (ec->view->b->dot == 0) {
25 if (ec->view->b->line->prev) {
26 e_buffer_up(ec->view->b);
27 e_buffer_eol(ec->view->b);
28 e_buffer_newline(ec->view->b);
29 e_buffer_down(ec->view->b);
31 else {
32 e_buffer_newline_first(ec->view->b);
35 else if (ec->view->b->dot == ec->view->b->line->used)
36 e_buffer_newline(ec->view->b);
37 else {
38 e_buffer_splitline(ec->view->b);
40 e_view_redraw(ec->view);
43 void e_cmd_ht(E_Eco *ec)
45 e_buffer_insert(ec->view->b, '\t');
46 e_view_redraw(ec->view);
49 void e_cmd_backspace(E_Eco *ec)
51 e_buffer_backspace(ec->view->b);
52 e_view_redraw(ec->view);
55 void e_cmd_write(E_Eco *ec)
57 char *buf;
59 if (!strcmp(ec->view->b->paths->file, "main")) {
60 buf= e_status_get_msg(ec, "File: ");
61 if (!buf)
62 return;
64 free((void *) ec->view->b->paths->file);
65 ec->view->b->paths->file= strdup(buf);
67 e_file_write(ec, ec->view->b);
70 void e_cmd_killline(E_Eco *ec)
72 e_buffer_killline(ec->view->b, 0);
73 e_view_redraw(ec->view);
76 void e_cmd_rotate(E_Eco *ec)
78 e_main_rotate(ec);
81 void e_cmd_goto(E_Eco *ec)
83 char *buf;
84 int line;
86 buf= e_status_get_msg(ec, "Line: ");
87 if (buf) {
88 line= atoi(buf);
89 e_buffer_goto(ec->view->b, line);
90 e_view_redraw(ec->view);
94 void e_cmd_find_file(E_Eco *ec)
96 E_Buffer *bf;
97 E_View *v;
98 char *buf;
99 int st;
101 buf= e_status_get_msg(ec, "Find File: ");
102 if (buf) {
103 bf= e_main_find(ec, buf);
104 if (bf) {
105 v= e_main_view_find(ec, bf);
106 e_view_unshow(ec->view);
107 e_view_show(v);
108 e_view_redraw(v);
109 ec->view= v;
111 else {
112 bf= e_file_read(buf, &st);
113 if (bf) {
114 v= e_view_new(ec->sc);
115 v->b= bf;
116 e_main_view_add(ec, v);
117 e_main_add(ec, bf);
119 e_view_show(v);
120 e_view_redraw(v);
121 e_view_unshow(ec->view);
122 ec->view= v;
124 else if (st == 2)
125 e_status_set_msg(ec, "(file is locked!)");
126 else if (st == 1)
127 e_status_set_msg(ec, "(file is not a regular file!)");
132 void e_cmd_cutline(E_Eco *ec)
134 e_buffer_killline(ec->view->b, 1);
135 e_view_redraw(ec->view);
138 void e_cmd_copyline(E_Eco *ec)
140 e_buffer_killline(ec->view->b, 2);
141 e_buffer_down(ec->view->b);
142 e_view_redraw(ec->view);
145 void e_cmd_paste(E_Eco *ec)
147 e_kill_paste(ec->view->b);
148 e_view_redraw(ec->view);
151 void e_cmd_cleankill(E_Eco *ec)
153 e_kill_clean();
156 void e_cmd_update(E_Eco *ec)
158 e_view_redraw(ec->view);
159 e_update(ec);
160 e_status_draw(ec);
161 e_screen_swap(ec->tr, ec->sc, 1);
162 e_term_flush();
165 void e_cmd_search_forward(E_Eco *ec)
167 char *buf;
169 buf= e_status_get_msg(ec, "Search: ");
170 if (buf) {
171 strcpy(ec->view->search, buf);
172 e_buffer_search(ec->view->b, ec->view->search, BUFFER_SEARCH_FORWARD);
173 e_status_set_msg(ec, "(Search: %s)", ec->view->search);
174 e_view_redraw(ec->view);
176 else if (ec->view->search) {
177 e_buffer_search(ec->view->b, ec->view->search, BUFFER_SEARCH_FORWARD);
178 e_status_set_msg(ec, "(Search: %s)", ec->view->search);
179 e_view_redraw(ec->view);
183 void e_cmd_search_backward(E_Eco *ec)
185 char *buf;
187 buf= e_status_get_msg(ec, "Search: ");
188 if (buf) {
189 strcpy(ec->view->search, buf);
190 e_buffer_search(ec->view->b, ec->view->search, BUFFER_SEARCH_BACKWARD);
191 e_status_set_msg(ec, "(Search: %s)", ec->view->search);
192 e_view_redraw(ec->view);
194 else if (ec->view->search) {
195 e_buffer_search(ec->view->b, ec->view->search, BUFFER_SEARCH_BACKWARD);
196 e_status_set_msg(ec, "(Search: %s)", ec->view->search);
197 e_view_redraw(ec->view);
201 void e_cmd_replace(E_Eco *ec)
203 char *buf;
204 int num;
206 buf= e_status_get_msg(ec, "Replace: ");
207 if (buf) {
208 strcpy(ec->view->search, buf);
209 buf= e_status_get_msg(ec, "With: ");
210 if (buf) {
211 num= e_buffer_replace(ec->view->b, ec->view->search, buf);
212 e_status_set_msg(ec, "(%d subsitutions)", num);
213 if (num)
214 e_view_redraw(ec->view);