unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] add emacsclient support to open with file:linum syntax
@ 2016-01-07 22:35 Jorge Alberto Garcia
  2016-01-08  7:42 ` Yuri Khan
  0 siblings, 1 reply; 43+ messages in thread
From: Jorge Alberto Garcia @ 2016-01-07 22:35 UTC (permalink / raw)
  To: emacs-devel

Hi !

I wrote a little patch to emacsclient,
Could you review it ?, this is my first attempt to contribute :)

Description

With this you can do this from cmdline:
$ emacsclient -q  -c lib-src/emacsclient.c:1593

in addition to have our already trusted way
lib-src/emacsclient -q   +1593 -c lib-src/emacsclient.c


- Why I did it ?
I found myself using tools that provides text location using
filepath:line but couldn't  use it directly by emacsclient.

-Jorge

diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index c3e5635..be9c9cc 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1593,7 +1593,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 +1747,21 @@ main (int argc, char **argv)
                   continue;
                 }
             }
+
+  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 +1783,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, " ");
         }



^ permalink raw reply related	[flat|nested] 43+ messages in thread
* Re: [PATCH] add emacsclient support to open with file:linum syntax
@ 2017-02-09  9:58 Toon Claes
  2017-02-09 13:22 ` Stefan Monnier
  0 siblings, 1 reply; 43+ messages in thread
From: Toon Claes @ 2017-02-09  9:58 UTC (permalink / raw)
  To: Emacs Devel; +Cc: jorge.garcia.gonzalez, eggert, monnier, kaushal.modi

On Thu, Mar 31, 2016 at 6:31 AM, Stefan Monnier <address@hidden> wrote:
> FWIW, I think we should try and arrange it so that the way emacsclient and
> server.el work together makes it possible to add such a new FILE:LINE
> syntax via an ELPA package (even if it might require an advice).
>
>
> Stefan

I am a bit sad this patch didn’t get applied, but I understand.

But I found this advice on SO: http://stackoverflow.com/a/3141456/89376

#+BEGIN_SRC emacs-lisp
;; Open files and goto lines like we see from g++ etc. i.e. file:line
(defadvice find-file (around find-file-line-number
                             (filename &optional wildcards)
                             activate)
  "Turn files like file.cpp:14 into file.cpp and going to the 14-th line."
  (save-match-data
    (let* ((matched (string-match "^\\(.*\\):\\([0-9]+\\):?$" filename))
           (line-number (and matched
                             (match-string 2 filename)
                             (string-to-number (match-string 2 filename))))
           (filename (if matched (match-string 1 filename) filename)))
      ad-do-it
      (when line-number
        ;; goto-line is for interactive use
        (goto-char (point-min))
        (forward-line (1- line-number))))))
#+END_SRC

Unfortunately it does not work with emacsclient.
So I could use some pointers on how to make it work with emacsclient.
Would it be possible to achieve this with an advice, since the original
patch was written in c.

Regards,
Toon


^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2017-02-14 13:57 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-07 22:35 [PATCH] add emacsclient support to open with file:linum syntax Jorge Alberto Garcia
2016-01-08  7:42 ` Yuri Khan
2016-01-08  8:08   ` Jorge Alberto Garcia
2016-01-08  8:59     ` Yuri Khan
2016-01-08 14:11       ` Jorge Alberto Garcia
2016-01-08  9:03   ` Eli Zaretskii
2016-01-08 14:13     ` Jorge Alberto Garcia
2016-01-08 15:39       ` Eli Zaretskii
2016-01-08 15:54         ` Kaushal Modi
2016-01-08 16:13           ` Jorge Alberto Garcia
2016-01-08 16:38             ` Kaushal Modi
2016-01-08 16:44               ` Jorge Alberto Garcia
2016-01-08 16:54                 ` Kaushal Modi
2016-01-08 17:52                   ` Jorge Alberto Garcia
2016-01-08 19:06                     ` Eli Zaretskii
2016-01-08 19:05                   ` Eli Zaretskii
2016-01-12 21:04                     ` John Wiegley
2016-01-12 21:26                       ` Jorge Alberto Garcia
2016-01-13  0:10                         ` John Wiegley
2016-01-13  0:46                           ` Jorge Alberto Garcia
2016-03-29 16:22                             ` Kaushal Modi
2016-03-29 17:30                               ` Jorge Alberto Garcia
2016-03-29 21:27                                 ` Paul Eggert
2016-03-29 22:35                                   ` Kaushal Modi
2016-03-29 23:08                                     ` Paul Eggert
2016-03-29 23:29                                       ` Jorge Alberto Garcia
2016-03-30  0:37                                         ` Paul Eggert
2016-03-30 14:21                                           ` Kaushal Modi
2016-03-30 16:42                                             ` Jorge Alberto Garcia
2016-03-31 12:31                                             ` Stefan Monnier
2016-03-31 14:24                                               ` Jorge Alberto Garcia
2016-01-08 19:19                   ` David Caldwell
2016-01-08 19:43                     ` Eli Zaretskii
2016-01-08 19:52                       ` David Caldwell
2016-01-08 20:33                         ` Jorge Alberto Garcia
2016-01-09 22:51                           ` Jorge Alberto Garcia
2016-01-10  8:22                             ` Yuri Khan
2016-01-10  8:37                               ` Jorge Alberto Garcia
2016-01-12 16:24                                 ` Jorge Alberto Garcia
2016-01-08 16:10         ` Jorge Alberto Garcia
  -- strict thread matches above, loose matches on Subject: below --
2017-02-09  9:58 Toon Claes
2017-02-09 13:22 ` Stefan Monnier
2017-02-14 13:57   ` Toon Claes

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).