Remove queue.[hc] - use GQueue instead of GeanyQueue.
Beep if there are no more snippet positions. Limit length of snippet positions queue to 20. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4204 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
8c1743cb3e
commit
b25e3e9650
@ -6,6 +6,11 @@
|
|||||||
* src/utils.c, src/utils.h:
|
* src/utils.c, src/utils.h:
|
||||||
Add foreach_dir() API macro.
|
Add foreach_dir() API macro.
|
||||||
Update API docs for utils_get_file_list().
|
Update API docs for utils_get_file_list().
|
||||||
|
* wscript, src/queue.c, src/editor.c, src/Makefile.am, src/queue.h,
|
||||||
|
po/POTFILES.in:
|
||||||
|
Remove queue.[hc] - use GQueue instead of GeanyQueue.
|
||||||
|
Beep if there are no more snippet positions.
|
||||||
|
Limit length of snippet positions queue to 20.
|
||||||
|
|
||||||
|
|
||||||
2009-09-16 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2009-09-16 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||||
|
|||||||
@ -26,7 +26,6 @@ src/plugins.c
|
|||||||
src/prefs.c
|
src/prefs.c
|
||||||
src/printing.c
|
src/printing.c
|
||||||
src/project.c
|
src/project.c
|
||||||
src/queue.c
|
|
||||||
src/sciwrappers.c
|
src/sciwrappers.c
|
||||||
src/search.c
|
src/search.c
|
||||||
src/socket.c
|
src/socket.c
|
||||||
|
|||||||
@ -36,7 +36,6 @@ SRCS = \
|
|||||||
prefs.c prefs.h \
|
prefs.c prefs.h \
|
||||||
printing.c printing.h \
|
printing.c printing.h \
|
||||||
project.c project.h \
|
project.c project.h \
|
||||||
queue.c queue.h \
|
|
||||||
sciwrappers.c sciwrappers.h \
|
sciwrappers.c sciwrappers.h \
|
||||||
search.c search.h \
|
search.c search.h \
|
||||||
socket.c socket.h \
|
socket.c socket.h \
|
||||||
|
|||||||
40
src/editor.c
40
src/editor.c
@ -59,7 +59,6 @@
|
|||||||
#include "keybindings.h"
|
#include "keybindings.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "projectprivate.h"
|
#include "projectprivate.h"
|
||||||
#include "queue.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Note: Avoid using SSM in files not related to scintilla, use sciwrappers.h instead. */
|
/* Note: Avoid using SSM in files not related to scintilla, use sciwrappers.h instead. */
|
||||||
@ -67,7 +66,7 @@
|
|||||||
|
|
||||||
|
|
||||||
static GHashTable *snippet_hash = NULL;
|
static GHashTable *snippet_hash = NULL;
|
||||||
static GeanyQueue *snippet_queue = NULL;
|
static GQueue *snippet_offsets = NULL;
|
||||||
static gint snippet_cursor_insert_pos;
|
static gint snippet_cursor_insert_pos;
|
||||||
|
|
||||||
/* holds word under the mouse or keyboard cursor */
|
/* holds word under the mouse or keyboard cursor */
|
||||||
@ -107,7 +106,7 @@ static void editor_auto_latex(GeanyEditor *editor, gint pos);
|
|||||||
void editor_snippets_free(void)
|
void editor_snippets_free(void)
|
||||||
{
|
{
|
||||||
g_hash_table_destroy(snippet_hash);
|
g_hash_table_destroy(snippet_hash);
|
||||||
queue_destroy(snippet_queue);
|
g_queue_free(snippet_offsets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -122,7 +121,7 @@ void editor_snippets_init(void)
|
|||||||
GKeyFile *userconfig = g_key_file_new();
|
GKeyFile *userconfig = g_key_file_new();
|
||||||
GHashTable *tmp;
|
GHashTable *tmp;
|
||||||
|
|
||||||
snippet_queue = queue_init();
|
snippet_offsets = g_queue_new();
|
||||||
|
|
||||||
sysconfigfile = g_strconcat(app->datadir, G_DIR_SEPARATOR_S, "snippets.conf", NULL);
|
sysconfigfile = g_strconcat(app->datadir, G_DIR_SEPARATOR_S, "snippets.conf", NULL);
|
||||||
userconfigfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "snippets.conf", NULL);
|
userconfigfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "snippets.conf", NULL);
|
||||||
@ -2173,11 +2172,11 @@ void editor_goto_next_snippet_cursor(GeanyEditor *editor)
|
|||||||
ScintillaObject *sci = editor->sci;
|
ScintillaObject *sci = editor->sci;
|
||||||
gint current_pos = sci_get_current_position(sci);
|
gint current_pos = sci_get_current_position(sci);
|
||||||
|
|
||||||
if (snippet_queue)
|
if (snippet_offsets && !g_queue_is_empty(snippet_offsets))
|
||||||
{
|
{
|
||||||
gint offset;
|
gint offset;
|
||||||
|
|
||||||
snippet_queue = queue_delete(snippet_queue, (gpointer*)&offset, FALSE);
|
offset = (gint)g_queue_pop_head(snippet_offsets);
|
||||||
if (current_pos > snippet_cursor_insert_pos)
|
if (current_pos > snippet_cursor_insert_pos)
|
||||||
snippet_cursor_insert_pos = offset + current_pos;
|
snippet_cursor_insert_pos = offset + current_pos;
|
||||||
else
|
else
|
||||||
@ -2185,6 +2184,10 @@ void editor_goto_next_snippet_cursor(GeanyEditor *editor)
|
|||||||
|
|
||||||
sci_set_current_position(sci, snippet_cursor_insert_pos, FALSE);
|
sci_set_current_position(sci, snippet_cursor_insert_pos, FALSE);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
utils_beep();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2197,7 +2200,7 @@ static gboolean snippets_complete_constructs(GeanyEditor *editor, gint pos, cons
|
|||||||
gssize cur_index = -1;
|
gssize cur_index = -1;
|
||||||
gint ft_id = FILETYPE_ID(editor->document->file_type);
|
gint ft_id = FILETYPE_ID(editor->document->file_type);
|
||||||
GHashTable *specials;
|
GHashTable *specials;
|
||||||
GeanyQueue *temp_list;
|
GList *temp_list = NULL;
|
||||||
const GeanyIndentPrefs *iprefs;
|
const GeanyIndentPrefs *iprefs;
|
||||||
gsize indent_size;
|
gsize indent_size;
|
||||||
gint cursor_steps, old_cursor = 0;
|
gint cursor_steps, old_cursor = 0;
|
||||||
@ -2212,7 +2215,6 @@ static gboolean snippets_complete_constructs(GeanyEditor *editor, gint pos, cons
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
temp_list = queue_init();
|
|
||||||
iprefs = editor_get_indent_prefs(editor);
|
iprefs = editor_get_indent_prefs(editor);
|
||||||
read_indent(editor, pos);
|
read_indent(editor, pos);
|
||||||
indent_size = strlen(indent);
|
indent_size = strlen(indent);
|
||||||
@ -2282,7 +2284,7 @@ static gboolean snippets_complete_constructs(GeanyEditor *editor, gint pos, cons
|
|||||||
if (i++ > 0)
|
if (i++ > 0)
|
||||||
{
|
{
|
||||||
cursor_steps += (nl_count * indent_size);
|
cursor_steps += (nl_count * indent_size);
|
||||||
queue_append(temp_list, GINT_TO_POINTER(cursor_steps - old_cursor));
|
temp_list = g_list_append(temp_list, GINT_TO_POINTER(cursor_steps - old_cursor));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2295,10 +2297,22 @@ static gboolean snippets_complete_constructs(GeanyEditor *editor, gint pos, cons
|
|||||||
utils_string_replace_all(pattern, "%newline%", editor_get_eol_char(editor));
|
utils_string_replace_all(pattern, "%newline%", editor_get_eol_char(editor));
|
||||||
utils_string_replace_all(pattern, "%ws%", whitespace);
|
utils_string_replace_all(pattern, "%ws%", whitespace);
|
||||||
g_free(whitespace);
|
g_free(whitespace);
|
||||||
/* We create a new list, where the cursor positions for the most recent
|
/* We put the cursor positions for the most recent
|
||||||
* parsed snipped come first, followed by the remaining positions */
|
* parsed snippet first, followed by any remaining positions */
|
||||||
if (temp_list->data)
|
i = 0;
|
||||||
snippet_queue = queue_concat_copy(temp_list, snippet_queue);
|
if (temp_list)
|
||||||
|
{
|
||||||
|
GList *node;
|
||||||
|
|
||||||
|
foreach_list(node, temp_list)
|
||||||
|
g_queue_push_nth(snippet_offsets, node->data, i++);
|
||||||
|
|
||||||
|
/* limit length of queue */
|
||||||
|
while (g_queue_get_length(snippet_offsets) > 20)
|
||||||
|
g_queue_pop_tail(snippet_offsets);
|
||||||
|
|
||||||
|
g_list_free(temp_list);
|
||||||
|
}
|
||||||
if (cur_index < 0)
|
if (cur_index < 0)
|
||||||
cur_index = pattern->len;
|
cur_index = pattern->len;
|
||||||
|
|
||||||
|
|||||||
144
src/queue.c
144
src/queue.c
@ -1,144 +0,0 @@
|
|||||||
/*
|
|
||||||
* queue.c - this file is part of Geany, a fast and lightweight IDE
|
|
||||||
*
|
|
||||||
* Copyright 2009 kugel. aka Thomas Martitz <thomas47(at)arcor(dot)de>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* WARNING: Do not use this in new code, use GQueue or GList instead - this code may be
|
|
||||||
* removed.
|
|
||||||
*
|
|
||||||
* This provides a simple single linked list, with some functions to modify it.
|
|
||||||
* Being a queue, you can append data only to the end of the list, and retrieve
|
|
||||||
* data from the beginning. Only the first node is directly visible, but with the foreach
|
|
||||||
* functions you can iterate through the entire list.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "geany.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "queue.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Allocates memory for queue_start, and sets next and data members to NULL */
|
|
||||||
GeanyQueue *queue_init(void)
|
|
||||||
{
|
|
||||||
return g_new0(GeanyQueue, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Returns true if q_node is the last node in a queue */
|
|
||||||
static gboolean queue_is_last_node(const GeanyQueue *q_node)
|
|
||||||
{
|
|
||||||
return (q_node->next == NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Appends a data in a new node at the end of the lst */
|
|
||||||
void queue_append(GeanyQueue *queue_start, gpointer data)
|
|
||||||
{
|
|
||||||
GeanyQueue *temp, *next;
|
|
||||||
|
|
||||||
if (queue_start == NULL || data == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (queue_start->data == NULL)
|
|
||||||
{
|
|
||||||
queue_start->data = data;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp = g_new0(GeanyQueue, 1);
|
|
||||||
temp->data = data;
|
|
||||||
temp->next = NULL;
|
|
||||||
|
|
||||||
next = queue_start;
|
|
||||||
while (! queue_is_last_node(next))
|
|
||||||
next = next->next;
|
|
||||||
next->next = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Removes and frees the first node in queue_start, and writes the data of the
|
|
||||||
* removed node into data.
|
|
||||||
* Returns a pointer to the new first item */
|
|
||||||
GeanyQueue *queue_delete(GeanyQueue *queue_start, gpointer *data, const gboolean free_data)
|
|
||||||
{
|
|
||||||
GeanyQueue *ret;
|
|
||||||
|
|
||||||
if (NULL == queue_start)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (data != NULL)
|
|
||||||
*data = queue_start->data;
|
|
||||||
|
|
||||||
if (free_data)
|
|
||||||
g_free(queue_start->data);
|
|
||||||
|
|
||||||
ret = queue_start->next;
|
|
||||||
g_free(queue_start);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Removes and frees the entire queue staring at queue_start */
|
|
||||||
void queue_destroy(GeanyQueue *queue_start)
|
|
||||||
{
|
|
||||||
while ((queue_start = queue_delete(queue_start, NULL, FALSE)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
typedef void (*ForeachFunc) (GeanyQueue *queue_start, gpointer data);
|
|
||||||
|
|
||||||
/* Iterates through param, and calls func with the node queue_start and each node in param */
|
|
||||||
static void queue_foreach_data_2(GeanyQueue *queue_start, ForeachFunc func, GeanyQueue *param)
|
|
||||||
{
|
|
||||||
GeanyQueue *temp = param;
|
|
||||||
|
|
||||||
if (! queue_start || ! param)
|
|
||||||
return;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
(*func) (queue_start, (temp->data));
|
|
||||||
}
|
|
||||||
while ((temp = temp->next));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Copies the data of each node in q1, then the data of each node in q2 to a newly
|
|
||||||
* created queue, using queue_append. Frees q1 and q2.
|
|
||||||
* Returns a pointer to the created queue. */
|
|
||||||
GeanyQueue *queue_concat_copy(GeanyQueue *q1, GeanyQueue *q2)
|
|
||||||
{
|
|
||||||
/* q1 + q2 = q3 *
|
|
||||||
* ->1->2 + ->4->5->6 = 4->5->6->1->2 */
|
|
||||||
GeanyQueue *ret = queue_init();
|
|
||||||
|
|
||||||
queue_foreach_data_2(ret, queue_append, q1);
|
|
||||||
queue_foreach_data_2(ret, queue_append, q2);
|
|
||||||
|
|
||||||
queue_destroy(q1);
|
|
||||||
queue_destroy(q2);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
48
src/queue.h
48
src/queue.h
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* queue.h - this file is part of Geany, a fast and lightweight IDE
|
|
||||||
*
|
|
||||||
* Copyright 2009 kugel. aka Thomas Martitz <thomas47(at)arcor(dot)de>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* WARNING: Do not use this in new code, use GQueue or GList instead - this code may be
|
|
||||||
* removed. */
|
|
||||||
|
|
||||||
#ifndef __QUEUE_H__
|
|
||||||
#define __QUEUE_H__
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _GeanyQueue
|
|
||||||
{
|
|
||||||
gpointer data;
|
|
||||||
struct _GeanyQueue *next;
|
|
||||||
} GeanyQueue;
|
|
||||||
|
|
||||||
|
|
||||||
GeanyQueue *queue_init(void);
|
|
||||||
|
|
||||||
void queue_append(GeanyQueue *queue_start, gpointer data);
|
|
||||||
|
|
||||||
GeanyQueue *queue_delete(GeanyQueue *queue_start, gpointer *data, const gboolean free_data);
|
|
||||||
|
|
||||||
GeanyQueue *queue_concat_copy(GeanyQueue *q1, GeanyQueue *q2);
|
|
||||||
|
|
||||||
void queue_destroy(GeanyQueue *queue_start);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __QUEUE_H__ */
|
|
||||||
2
wscript
2
wscript
@ -109,7 +109,7 @@ geany_sources = [
|
|||||||
'src/highlighting.c', 'src/interface.c', 'src/keybindings.c',
|
'src/highlighting.c', 'src/interface.c', 'src/keybindings.c',
|
||||||
'src/keyfile.c', 'src/log.c', 'src/main.c', 'src/msgwindow.c', 'src/navqueue.c', 'src/notebook.c',
|
'src/keyfile.c', 'src/log.c', 'src/main.c', 'src/msgwindow.c', 'src/navqueue.c', 'src/notebook.c',
|
||||||
'src/plugins.c', 'src/pluginutils.c', 'src/prefix.c', 'src/prefs.c', 'src/printing.c', 'src/project.c',
|
'src/plugins.c', 'src/pluginutils.c', 'src/prefix.c', 'src/prefs.c', 'src/printing.c', 'src/project.c',
|
||||||
'src/queue.c', 'src/sciwrappers.c', 'src/search.c', 'src/socket.c', 'src/stash.c',
|
'src/sciwrappers.c', 'src/search.c', 'src/socket.c', 'src/stash.c',
|
||||||
'src/symbols.c',
|
'src/symbols.c',
|
||||||
'src/templates.c', 'src/toolbar.c', 'src/tools.c', 'src/treeviews.c',
|
'src/templates.c', 'src/toolbar.c', 'src/tools.c', 'src/treeviews.c',
|
||||||
'src/ui_utils.c', 'src/utils.c' ]
|
'src/ui_utils.c', 'src/utils.c' ]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user