diff options
| author | Karoly Lorentey | 2006-03-26 16:34:35 +0000 |
|---|---|---|
| committer | Karoly Lorentey | 2006-03-26 16:34:35 +0000 |
| commit | 2828d5f9d4f097228e9b64542fd74de4c47135e5 (patch) | |
| tree | db326e57114dedeb6b74f050dd485fd6fe1184d3 /lib-src | |
| parent | 59b3194ca9708b904c87d52bb9e074e32b7d9089 (diff) | |
| download | emacs-2828d5f9d4f097228e9b64542fd74de4c47135e5.tar.gz emacs-2828d5f9d4f097228e9b64542fd74de4c47135e5.zip | |
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
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/emacsclient.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 42c90934b4b..b538b0093af 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -248,6 +248,83 @@ xstrdup (const char *s) | |||
| 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. |
| @@ -709,6 +786,20 @@ To start the server in Emacs, type \"M-x server-start\".\n", | |||
| 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 "); |