emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] add emacsclient support to open with file:linum syntax


From: Jorge Alberto Garcia
Subject: Re: [PATCH] add emacsclient support to open with file:linum syntax
Date: Sat, 9 Jan 2016 16:51:10 -0600

On Fri, Jan 8, 2016 at 2:33 PM, Jorge Alberto Garcia
<address@hidden> wrote:
> On Fri, Jan 8, 2016 at 1:52 PM, David Caldwell <address@hidden> wrote:
>> On 1/8/16 11:43 AM, Eli Zaretskii wrote:
>>>> Cc: Eli Zaretskii <address@hidden>, Yuri Khan <address@hidden>,
>>>>         Emacs developers <address@hidden>
>>>> From: David Caldwell <address@hidden>
>>>> Date: Fri, 8 Jan 2016 11:19:26 -0800
>>>>
>>>> Why not instead of adding the new option, rearrange the logic so that it
>>>> only tries to parse the ":linenum" part if the file doesn't exist?
>>>
>>> Because both 'filename' and 'filename:1234' could exist.
>>
>> Ah. Very good point.
>>
>>> Really, I don't understand why should we come with fancy syntax when a
>>> new option will unequivocally tell which case is it.
>>
>> It just seemed nicer to have it be automatic if it was possible. An
>> option is fine.
> David, that was actually a clever workaround.
>
> Following Eli's observation
>
> I will add a new flag using Yuri's suggested name
> Flag name is open for feedback !
>
>>
>> -David

Hi folks,

I added a new flag as indicated by Eli Zaretskii using Yuri Khan's
suggested flag name:

diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index c3e5635..3bff612 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -151,6 +151,9 @@ int emacs_pid = 0;
    be used for the new frame.  */
 const char *frame_parameters = NULL;

+/* Nonzero means filename:line:column syntax support is enable  */
+int filename_with_line_col = 0;
+
 static _Noreturn void print_help_and_exit (void);


@@ -172,6 +175,7 @@ struct option longopts[] =
   { "server-file", required_argument, NULL, 'f' },
   { "display", required_argument, NULL, 'd' },
   { "parent-id", required_argument, NULL, 'p' },
+  { "files-with-line-col", no_argument, NULL, 'l' },
   { 0, 0, 0, 0 }
 };

@@ -461,9 +465,9 @@ decode_options (int argc, char **argv)
     {
       int opt = getopt_long_only (argc, argv,
 #ifndef NO_SOCKETS_IN_FILE_SYSTEM
-     "VHneqa:s:f:d:F:tc",
+     "lVHneqa:s:f:d:F:tc",
 #else
-     "VHneqa:f:d:F:tc",
+  "lVHneqa:f:d:F:tc",
 #endif
      longopts, 0);

@@ -537,6 +541,9 @@ decode_options (int argc, char **argv)
         case 'F':
           frame_parameters = optarg;
           break;
+ case 'l':
+  filename_with_line_col = 1;
+  break;

  default:
   message (true, "Try '%s --help' for more information\n", progname);
@@ -637,8 +644,9 @@ The following OPTIONS are accepted:\n\
  Editor to fallback to if the server is not running\n"
 " If EDITOR is the empty string, start Emacs in daemon\n\
  mode and try connecting again\n"
-"\n\
-Report bugs with M-x report-emacs-bug.\n");
+"-l --files-with-line-col\n\
+ Support embedded location syntax FILENAME[:LINE[:COLUMN]]\n"
+"Report bugs with M-x report-emacs-bug.\n");
   exit (EXIT_SUCCESS);
 }

@@ -1593,7 +1601,7 @@ main (int argc, char **argv)
   char string[BUFSIZ+1];
   int start_daemon_if_needed;
   int exit_status = EXIT_SUCCESS;
-
+  char *lineDst;
   main_argv = argv;
   progname = argv[0];

@@ -1747,6 +1755,23 @@ main (int argc, char **argv)
                   continue;
                 }
             }
+
+  if(filename_with_line_col != 0)
+    {
+      lineDst = index(argv[i],':');
+      if ( lineDst != NULL)
+ {
+  char *p = lineDst + 1;
+  while (isdigit ((unsigned char) *p) || *p == ':') p++;
+  if (*p == 0)
+    {
+      send_to_emacs (emacs_socket, "-position ");
+      *lineDst='+';
+      quote_argument (emacs_socket, lineDst);
+      send_to_emacs (emacs_socket, " ");
+    }
+ }
+    }
 #ifdef WINDOWSNT
   else if (! file_name_absolute_p (argv[i])
    && (isalpha (argv[i][0]) && argv[i][1] == ':'))
@@ -1768,7 +1793,10 @@ main (int argc, char **argv)
     }
 #endif

-          send_to_emacs (emacs_socket, "-file ");
+  send_to_emacs (emacs_socket, "-file ");
+  if(lineDst != NULL){
+    *lineDst = 0;
+  }
           quote_argument (emacs_socket, argv[i]);
           send_to_emacs (emacs_socket, " ");
         }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]