SF.net SVN: geany: [1227] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Wed Jan 24 22:38:54 UTC 2007


Revision: 1227
          http://svn.sourceforge.net/geany/?rev=1227&view=rev
Author:   eht16
Date:     2007-01-24 14:38:53 -0800 (Wed, 24 Jan 2007)

Log Message:
-----------
Added command line option --column to allow setting the initial column for the first opened file on command line.
Don't apply the --line and --column options to the first opened session file.
Make --line and --column options work for opening files in an already running instance.

Modified Paths:
--------------
    trunk/doc/geany.1.in
    trunk/doc/geany.docbook
    trunk/src/document.c
    trunk/src/main.c
    trunk/src/main.h
    trunk/src/socket.c

Modified: trunk/doc/geany.1.in
===================================================================
--- trunk/doc/geany.1.in	2007-01-24 19:52:12 UTC (rev 1226)
+++ trunk/doc/geany.1.in	2007-01-24 22:38:53 UTC (rev 1227)
@@ -16,11 +16,13 @@
 Set initial line number for the first opened file
 
 .SH "OPTIONS"
+.IP "\fB\fP           \fB\-\-column\fP         " 10
+Set initial column number for the first opened file (useful in conjunction with --line).
 .IP "\fB-c\fP           \fB\-\-config\fP         " 10
 Use an alternate configuration directory. Default configuration directory is
 ~/.geany/ and there resides geany.conf and some template files.
 .IP "\fB-d\fP           \fB\-\-debug\fP         " 10
-Runs Geany in debug mode, which means being verbose and printing lots of information.
+Run Geany in debug mode, which means being verbose and printing lots of information.
 .IP "\fB-i\fP           \fB\-\-new-instance\fP         " 10
 Don't open files in a running instance, force opening a new instance.
 Only available if Geany was compiled with support for Sockets.

Modified: trunk/doc/geany.docbook
===================================================================
--- trunk/doc/geany.docbook	2007-01-24 19:52:12 UTC (rev 1226)
+++ trunk/doc/geany.docbook	2007-01-24 22:38:53 UTC (rev 1227)
@@ -236,6 +236,12 @@
 						</thead>
 						<tbody>
 							<row>
+								<entry></entry>
+								<entry>--column</entry>
+								<entry>Set initial column number for the first opened file.
+								</entry>
+							</row>
+							<row>
 								<entry>-c dir_name</entry>
 								<entry>--config=directory_name</entry>
 								<entry>Use an alternate configuration directory. Default

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2007-01-24 19:52:12 UTC (rev 1226)
+++ trunk/src/document.c	2007-01-24 22:38:53 UTC (rev 1227)
@@ -737,10 +737,10 @@
 	// update line number margin width
 	sci_set_line_numbers(doc_list[idx].sci, app->show_linenumber_margin, 0);
 
-	if (cl_options.goto_line >= 0)
+	if (! app->opening_session_files && cl_options.goto_line >= 0)
 	{	// goto line which was specified on command line and then undefine the line
 		sci_goto_line(doc_list[idx].sci, cl_options.goto_line - 1, TRUE);
-		sci_scroll_to_line(doc_list[idx].sci, -1, 0.5);
+		sci_scroll_to_line(doc_list[idx].sci, cl_options.goto_line - 1, 0.5);
 		cl_options.goto_line = -1;
 	}
 	else if (pos >= 0)
@@ -749,6 +749,12 @@
 		if (reload)
 			sci_scroll_to_line(doc_list[idx].sci, -1, 0.5);
 	}
+	if (! app->opening_session_files && cl_options.goto_column >= 0)
+	{	// goto column which was specified on command line and then undefine the column
+		gint cur_pos = sci_get_current_position(doc_list[idx].sci);
+		sci_set_current_position(doc_list[idx].sci, cur_pos + cl_options.goto_column);
+		cl_options.goto_column = -1;
+	}
 
 	if (! reload)
 	{

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2007-01-24 19:52:12 UTC (rev 1226)
+++ trunk/src/main.c	2007-01-24 22:38:53 UTC (rev 1227)
@@ -86,6 +86,7 @@
 
 static GOptionEntry entries[] =
 {
+	{ "column", 0, 0, G_OPTION_ARG_INT, &cl_options.goto_column, N_("set initial column number for the first opened file (useful in conjunction with --line)"), NULL },
 	{ "config", 'c', 0, G_OPTION_ARG_FILENAME, &alternate_config, N_("use an alternate configuration directory"), NULL },
 	{ "debug", 'd', 0, G_OPTION_ARG_NONE, &debug_mode, N_("runs in debug mode (means being verbose)"), NULL },
 	{ "generate-data-files", 'g', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &generate_datafiles, "", NULL },
@@ -401,6 +402,7 @@
 	// first initialise cl_options fields with default values
 	cl_options.load_session = TRUE;
 	cl_options.goto_line = -1;
+	cl_options.goto_column = -1;
 
 	context = g_option_context_new(_(" - A fast and lightweight IDE"));
 	g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);

Modified: trunk/src/main.h
===================================================================
--- trunk/src/main.h	2007-01-24 19:52:12 UTC (rev 1226)
+++ trunk/src/main.h	2007-01-24 22:38:53 UTC (rev 1227)
@@ -29,6 +29,7 @@
 {
 	gboolean load_session;
 	gint goto_line;
+	gint goto_column;
 } CommandLineOptions;
 
 extern CommandLineOptions cl_options;

Modified: trunk/src/socket.c
===================================================================
--- trunk/src/socket.c	2007-01-24 19:52:12 UTC (rev 1226)
+++ trunk/src/socket.c	2007-01-24 22:38:53 UTC (rev 1227)
@@ -21,7 +21,22 @@
  * $Id$
  */
 
+/*
+ * Little dev doc:
+ * Each command which is sent between two instances (see send_open_command and
+ * socket_lock_input_cb) should have the following scheme:
+ * command name\n
+ * data\n
+ * data\n
+ * ...
+ * .\n
+ * The first thing should be the command name followed by the data belonging to the command and
+ * to mark the end of data send a single '.'. Each message should be ended with \n.
+ *
+ * At the moment the commands open, line and column are available.
+ */
 
+
 #include "geany.h"
 
 #ifdef HAVE_SOCKET
@@ -37,6 +52,7 @@
 # include <winsock2.h>
 # include <ws2tcpip.h>
 #endif
+#include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
 
@@ -85,6 +101,24 @@
 	g_return_if_fail(argc > 1);
 	geany_debug("using running instance of Geany");
 
+	if (cl_options.goto_line >= 0)
+	{
+		gchar *line = g_strdup_printf("%d\n", cl_options.goto_line);
+		socket_fd_write_all(sock, "line\n", 5);
+		socket_fd_write_all(sock, line, strlen(line));
+		socket_fd_write_all(sock, ".\n", 2);
+		g_free(line);
+	}
+
+	if (cl_options.goto_column >= 0)
+	{
+		gchar *col = g_strdup_printf("%d\n", cl_options.goto_column);
+		socket_fd_write_all(sock, "column\n", 7);
+		socket_fd_write_all(sock, col, strlen(col));
+		socket_fd_write_all(sock, ".\n", 2);
+		g_free(col);
+	}
+
 	socket_fd_write_all(sock, "open\n", 5);
 
 	for(i = 1; i < argc && argv[i] != NULL; i++)
@@ -364,24 +398,43 @@
 	sock = accept(fd, (struct sockaddr *)&caddr, &caddr_len);
 
 	// first get the command
-	if (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && strncmp(buf, "open", 4) == 0)
+	while (socket_fd_gets(sock, buf, sizeof(buf)) != -1)
 	{
-		geany_debug("remote command: open");
-		while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
+		if (strncmp(buf, "open", 4) == 0)
 		{
-			g_strstrip(buf); // remove \n char
+			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
+			{
+				g_strstrip(buf); // remove \n char
 
-			if (g_file_test(buf, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
-				document_open_file(-1, buf, 0, FALSE, NULL, NULL);
-			else
-				geany_debug("got data from socket, but it does not look like a filename");
-		}
-		gtk_window_deiconify(GTK_WINDOW(app->window));
+				if (g_file_test(buf, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
+					document_open_file(-1, buf, 0, FALSE, NULL, NULL);
+				else
+					geany_debug("got data from socket, but it does not look like a filename");
+			}
+			gtk_window_deiconify(GTK_WINDOW(app->window));
 #ifdef G_OS_WIN32
-		gtk_window_present(GTK_WINDOW(app->window));
+			gtk_window_present(GTK_WINDOW(app->window));
 #endif
+		}
+		else if (strncmp(buf, "line", 4) == 0)
+		{
+			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
+			{
+				g_strstrip(buf); // remove \n char
+				// on any error we get 0 which should be save enough as fallback
+				cl_options.goto_line = atoi(buf);
+			}
+		}
+		else if (strncmp(buf, "column", 6) == 0)
+		{
+			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
+			{
+				g_strstrip(buf); // remove \n char
+				// on any error we get 0 which should be save enough as fallback
+				cl_options.goto_column = atoi(buf);
+			}
+		}
 	}
-
 	socket_fd_close(sock);
 
 	return TRUE;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list