Mercurial > emacs
comparison lib-src/emacsclient.c @ 83499:0fe580113f72
Set `default-directory' in *scratch* to the current directory of emacsclient.
* lib-src/emacsclient.c (get_current_dir_name): New function, copied here
from sysdep.c.
(main): Use it to send over the current directory.
* lisp/server.el (server-process-filter): Accept `-dir' command. Set
`default-directory' of the *scratch* buffer on connect, if applicable.
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-539
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Sun, 26 Mar 2006 16:34:35 +0000 |
parents | b98066f4aa10 |
children | 0a651d0085ee |
comparison
equal
deleted
inserted
replaced
83498:f0987e2f27e2 | 83499:0fe580113f72 |
---|---|
246 exit (EXIT_FAILURE); | 246 exit (EXIT_FAILURE); |
247 } | 247 } |
248 return result; | 248 return result; |
249 } | 249 } |
250 | 250 |
251 /* From sysdep.c */ | |
252 #if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME) | |
253 | |
254 /* Return the current working directory. Returns NULL on errors. | |
255 Any other returned value must be freed with free. This is used | |
256 only when get_current_dir_name is not defined on the system. */ | |
257 char* | |
258 get_current_dir_name () | |
259 { | |
260 char *buf; | |
261 char *pwd; | |
262 struct stat dotstat, pwdstat; | |
263 /* If PWD is accurate, use it instead of calling getwd. PWD is | |
264 sometimes a nicer name, and using it may avoid a fatal error if a | |
265 parent directory is searchable but not readable. */ | |
266 if ((pwd = getenv ("PWD")) != 0 | |
267 && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1]))) | |
268 && stat (pwd, &pwdstat) == 0 | |
269 && stat (".", &dotstat) == 0 | |
270 && dotstat.st_ino == pwdstat.st_ino | |
271 && dotstat.st_dev == pwdstat.st_dev | |
272 #ifdef MAXPATHLEN | |
273 && strlen (pwd) < MAXPATHLEN | |
274 #endif | |
275 ) | |
276 { | |
277 buf = (char *) malloc (strlen (pwd) + 1); | |
278 if (!buf) | |
279 return NULL; | |
280 strcpy (buf, pwd); | |
281 } | |
282 #ifdef HAVE_GETCWD | |
283 else | |
284 { | |
285 size_t buf_size = 1024; | |
286 buf = (char *) malloc (buf_size); | |
287 if (!buf) | |
288 return NULL; | |
289 for (;;) | |
290 { | |
291 if (getcwd (buf, buf_size) == buf) | |
292 break; | |
293 if (errno != ERANGE) | |
294 { | |
295 int tmp_errno = errno; | |
296 free (buf); | |
297 errno = tmp_errno; | |
298 return NULL; | |
299 } | |
300 buf_size *= 2; | |
301 buf = (char *) realloc (buf, buf_size); | |
302 if (!buf) | |
303 return NULL; | |
304 } | |
305 } | |
306 #else | |
307 else | |
308 { | |
309 /* We need MAXPATHLEN here. */ | |
310 buf = (char *) malloc (MAXPATHLEN + 1); | |
311 if (!buf) | |
312 return NULL; | |
313 if (getwd (buf) == NULL) | |
314 { | |
315 int tmp_errno = errno; | |
316 free (buf); | |
317 errno = tmp_errno; | |
318 return NULL; | |
319 } | |
320 } | |
321 #endif | |
322 return buf; | |
323 } | |
324 #endif | |
325 | |
326 | |
327 | |
251 /* In STR, insert a & before each &, each space, each newline, and | 328 /* In STR, insert a & before each &, each space, each newline, and |
252 any initial -. Change spaces to underscores, too, so that the | 329 any initial -. Change spaces to underscores, too, so that the |
253 return value never contains a space. | 330 return value never contains a space. |
254 | 331 |
255 Does not change the string. Outputs the result to STREAM. */ | 332 Does not change the string. Outputs the result to STREAM. */ |
707 quote_argument (environ[i], out); | 784 quote_argument (environ[i], out); |
708 fprintf (out, " "); | 785 fprintf (out, " "); |
709 } | 786 } |
710 } | 787 } |
711 | 788 |
789 /* Send over our current directory. */ | |
790 if (!current_frame) | |
791 { | |
792 char *dir = get_current_dir_name (); | |
793 if (dir) | |
794 { | |
795 fprintf (out, "-dir "); | |
796 quote_argument (dir, out); | |
797 fprintf (out, "/"); | |
798 fprintf (out, " "); | |
799 free (dir); | |
800 } | |
801 } | |
802 | |
712 retry: | 803 retry: |
713 if (nowait) | 804 if (nowait) |
714 fprintf (out, "-nowait "); | 805 fprintf (out, "-nowait "); |
715 | 806 |
716 if (current_frame) | 807 if (current_frame) |