summaryrefslogtreecommitdiff
path: root/src/editor.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2004-12-13 01:04:15 +0000
committersabetts <sabetts>2004-12-13 01:04:15 +0000
commitf90ee8e9dfcb3ab286c5202e96a0715429f0e4e7 (patch)
tree43fd7965bcae0bf813f9609c4bf815cb6df09aff /src/editor.c
parentf6f24bd90f416993e1621266081bfc9419925495 (diff)
downloadratpoison-f90ee8e9dfcb3ab286c5202e96a0715429f0e4e7.zip
* src/sbuf.c (sbuf_concat): call sbuf_nconcat. move bulk of body
to sbuf_nconcat. (sbuf_nconcat): new function * src/globals.c (init_globals): new function * src/main.c (main): call init_globals. * src/globals.c: include unistd.h. (x_export_selection): new function (set_nselection): likewise (set_selection): call x_export_selection (get_cut_buffer): new function (get_primary_selection): likewise (get_selection): likewise * src/editor.c (editor_kill_word): add the deleted text to the X11 selection (editor_backward_kill_word): likewise (editor_kill_line): likewise (backward_kill_line): new fuction (editor_backward_kill_line): add the deleted text to the X11 selection. call backward_kill_line. (paste_cut_buffer): remove function (paste_primary_selection): likewise (editor_paste_selection): call get_selection to get the X11 selection. (editor_complete): call backward_kill_line instead of editor_backward_kill_line. * src/ratpoison.h: Include string.h. Include X11/XAtom.h. * src/globals.c (selection): new global (set_selection): new function * src/events.c: include X11/Xmd.h (selection_request): new function (selection_clear): new function (delegate_event): call selection_request and selection_clear for SelectionRequest and SelectionClear events. * src/actions.c (user_commands): remove duplicate focusprev entry. Add putsel. Add getsel. (cmd_putsel): new function (cmd_getsel): new function * contrib/genrpbindings: add a missing paren to the elisp bindings.
Diffstat (limited to 'src/editor.c')
-rw-r--r--src/editor.c146
1 files changed, 35 insertions, 111 deletions
diff --git a/src/editor.c b/src/editor.c
index 3a36291..6f312e0 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -257,6 +257,7 @@ static edit_status
editor_kill_word (rp_input_line *line)
{
int i, diff;
+
if (line->position < line->length)
{
@@ -265,6 +266,9 @@ editor_kill_word (rp_input_line *line)
diff = i - line->position;
+ /* Add the word to the X11 selection. */
+ set_nselection (&line->buffer[line->position], diff);
+
for (i = line->position; i <= line->length - diff; i++)
line->buffer[i] = line->buffer[i + diff];
@@ -288,6 +292,9 @@ editor_backward_kill_word (rp_input_line *line)
line->position = i;
+ /* Add the word to the X11 selection. */
+ set_nselection (&line->buffer[line->position], diff);
+
for (; i <= line->length - diff; i++)
line->buffer[i] = line->buffer[i + diff];
@@ -302,6 +309,9 @@ editor_kill_line (rp_input_line *line)
{
if (line->position < line->length)
{
+ /* Add the line to the X11 selection. */
+ set_selection (&line->buffer[line->position]);
+
line->length = line->position;
line->buffer[line->length] = 0;
}
@@ -309,19 +319,33 @@ editor_kill_line (rp_input_line *line)
return EDIT_DELETE;
}
-static edit_status
-editor_backward_kill_line (rp_input_line *line)
+/* Do the dirty work of killing a line backwards. */
+static void
+backward_kill_line (rp_input_line *line)
{
int i;
+ /* If we're at the beginning, we have nothing to do. */
if (line->position <= 0)
- return EDIT_NO_OP;
+ return;
for (i = line->position; i<= line->length; i++)
line->buffer[i - line->position] = line->buffer[i];
line->length -= line->position;
line->position = 0;
+}
+
+static edit_status
+editor_backward_kill_line (rp_input_line *line)
+{
+ if (line->position <= 0)
+ return EDIT_NO_OP;
+
+ /* Add the line to the X11 selection. */
+ set_nselection (line->buffer, line->position);
+
+ backward_kill_line (line);
return EDIT_DELETE;
}
@@ -469,118 +493,18 @@ editor_enter (rp_input_line *line)
}
static edit_status
-paste_cut_buffer (rp_input_line *line)
-{
- int nbytes;
- char *data;
- edit_status status;
-
- PRINT_DEBUG (("trying the cut buffer\n"));
-
- data = XFetchBytes (dpy, &nbytes);
-
- if (data)
- {
-/* status = editor_insert (line, data, nbytes); */
- status = editor_insert (line, data);
- XFree (data);
- }
- else
- {
- status = EDIT_NO_OP;
- }
-
- return status;
-}
-
-static edit_status
-paste_primary_selection (rp_input_line *line)
-{
- Atom actual_type;
- rp_screen *s = current_screen ();
- int actual_format;
- unsigned long nitems;
- unsigned long offset;
- unsigned long bytes_after;
- unsigned char *data;
-
- if (XGetWindowProperty (dpy, s->input_window, rp_selection, 0, 0, False, XA_STRING, &actual_type, &actual_format, &nitems, &bytes_after, &data) == Success)
- {
- if (data)
- {
- XFree (data);
- data = NULL;
- }
-
- PRINT_DEBUG (("actual_type = %ld, actual_format = %d, bytes_after = %ld\n", actual_type, actual_format, bytes_after));
-
- if (actual_type != XA_STRING || actual_format != 8)
- {
- PRINT_DEBUG (("selection data is invalid\n"));
- if (data)
- XFree (data);
- return EDIT_NO_OP;
- }
-
- offset = 0;
-
- while (bytes_after > 0)
- {
- if (XGetWindowProperty (dpy, s->input_window, rp_selection, offset / 4, bytes_after / 4 + 1, False, XA_STRING, &actual_type, &actual_format, &nitems, &bytes_after, &data) != Success)
- break;
-
- PRINT_DEBUG (("bytes_after = %ld, nitems = %ld, data = '%s'\n", bytes_after, nitems, data));
-
- nitems *= actual_format / 8;
- offset += nitems;
-
-/* editor_insert (line, data, nitems); */
- editor_insert (line, (char *)data);
-
- PRINT_DEBUG (("bytes_after = %ld, nitems = %ld, data = '%s'\n", bytes_after, nitems, data));
-
- XFree (data);
- }
- }
-
- /* notify the owner that the data has been transferred */
- XDeleteProperty(dpy, s->input_window, rp_selection);
-
- return EDIT_INSERT;
-}
-
-static edit_status
editor_paste_selection (rp_input_line *line)
{
- Atom property;
- XEvent ev;
- rp_screen *s = current_screen ();
- int loops = 1000;
-
- /* be a good icccm citizen */
- XDeleteProperty (dpy, s->input_window, rp_selection);
- /* TODO: we shouldn't use CurrentTime here, use the time of the XKeyEvent, should we fake it? */
- XConvertSelection (dpy, XA_PRIMARY, XA_STRING, rp_selection, s->input_window, CurrentTime);
-
- while (!XCheckTypedWindowEvent (dpy, s->input_window, SelectionNotify, &ev))
+ char *text;
+ text = get_selection();
+ if (text)
{
- if (loops == 0)
- {
- PRINT_ERROR (("selection request timed out\n"));
- return EDIT_NO_OP;
- }
- usleep (10000);
- loops--;
+ editor_insert(line, text);
+ free (text);
+ return EDIT_INSERT;
}
-
- PRINT_DEBUG (("SelectionNotify event\n"));
-
- property = ev.xselection.property;
-
- if (property != None)
- return paste_primary_selection (line);
else
- return paste_cut_buffer (line);
+ return EDIT_NO_OP;
}
static edit_status
@@ -604,7 +528,7 @@ editor_complete (rp_input_line *line, int direction)
return EDIT_NO_OP;
/* Insert the completion. */
- editor_backward_kill_line (line);
+ backward_kill_line (line);
editor_insert (line, s);
return EDIT_COMPLETE;