Emacs quick question?

I'm pretty sure this isn't the best place.. maybe not even the right place??
to post this, but i'll give it a try since I've been searching for this info non-stop on Emacs wiki and only found non-working answers

A few notes before my question ::
Quick Notes
1- I'm not good with windows stuff (nor mac or linux if that matters at all) so im pretty sure i did the wrong command somewhere and its this that is causing my problem
2- I'm new to programming and such, take it easy please <3
3- English not my native language so might have a lot of typos/spelling and such

Info (Windows 8.1 64-bit - GNU EMACS 23.4.1)
Q:
I've download Emacs 23.4~ same as casey and I've been using this for sometime now, my .emacs are really close to his, I've only changed a few commands and the title settings to match the directory. The problem is: if i try to open(be it on terminal or not) a .txt or any archive that is set to be opened by Emacs instead of opening in a new "buffer"(i think this is the correct term?) it opens on a completely new instance which implies i have 1029381092832 emacs windows open =(

More Info:
1- i call emacs from terminal by a custom %PATH% set on a folder \custom_cmd , which has my .lnk and .bat
2- my default for .txt is emacs and was set using ftype/assoc
3- my emacs.bat
@echo off
"c:\path\to\emacs\runemacs.exe" %1


... I'm not really sure how to fix this? i've tried a bunch of stuff I've found on google/wiki


TL;DR
i just want to make sure emacs opens in a new frame instead of a new instance everytime i open a file outside emacs.

well thanks for reading this =]
that was one of the first things i've tried.. didn't work sadly, it still loads files on new instances instead of a buffer within the open instace
Well then I can't help you, sorry. I either open files derictly from emacs or do drag-n-drop on already open instance.
I am using emacs on linux, so the process is different I'm sure. But I run emacs as a "daemon" (just a background process that's always running).

for me the command is

"emacs --daemon"

and then if I want to open a new frame I run:

"emacsclient"

and it will use the same emacs instance.
Here is the link for setting it up on Windows http://www.emacswiki.org/emacs/EmacsClient#toc4

although I've never tried it so I can't help much!
that sounds an interesting idea, even if it doesn't fix my problem would reduce the opening time by a good margin =]

i'll give it a try and see if i can set it up on windows and edit my comment here later,
thanks for the help guys o/
Here's how I do it.

First, I always launch emacs through a .bat file, here's what it contains:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
@ECHO OFF

:: CUSTOMIZE THESE
set install_dir=YOUR_EMACS_BIN_DIR_HERE
set emacs_config_dir=YOUR_EMACS.D_PATH_HERE

set buffer=%1
if ""%1""=="""" set buffer=new
    %install_dir%\emacsclient.exe --no-wait ^
    --alternate-editor "%install_dir%\runemacs.exe" ^
    -f "%emacs_config_dir%\server" %buffer%


If Emacs, isn't running, it launches a new instance (that's the "runemacs.exe" bit). If it is running, it opens a new buffer in the running instance.

You can call the script on the command line and pass it a filename as parameter. If none is provide it will open a buffer called "new". You can also drag and drop a file on the script via the explorer.

A small note on the "server" file: Basically, to detect if an instance is running, emacs will check a file, called the server file. This file records the currently running emacs process, if any. Here I opt to specify the server file explicitly (otherwise it uses an obscure temporary location; and I don't remember exactly why but I had problem with that).

Second, you need the include the line "(server-start)" at the end of your init.el (or .emacs) file. If you don't do this, emacs won't write to the server file, and each invocation of the script will launch its own instance.

More stuff (including how to do this little dance on Linux & Mac OSX) here: https://github.com/norswap/.emacs.d

Edited by norswap on
@norswap

i've tried implementing your .bat on my end and got some errors which im not sure what
is causing them, but i believe is the version i use?

[spoiler= my current .bat and terminal errors]

[/spoiler]
It seems the problem is caused by the fact that you have a double quote at the start of the install_dir variable, but not at the end.

I see what you were trying to do (you put the closing double quote after "emacsclient.exe", but it doesn't seem to work that way, since putting the same modification in my emacs.bat file produces the same error. (I avoid the issue because my directions don't have spaces in them, so I don't need to use quotes.)

It looks like wrapping the whole variable initializer in double quotes will work. For instance, this works:

1
2
3
4
5
6
7
8
set installdir="C:\Chocolatey\lib\Emacs.24.3\tools\emacs-24.3\bin"
set repodir="C:\Dropbox\.emacs.d"

set buffer=%1
if ""%1""=="""" set buffer=new
%installdir%\emacsclient.exe --no-wait ^
    --alternate-editor %installdir%\runemacs.exe ^
    -f %repodir%\files-%USERDOMAIN%-%USERNAME%\server %buffer%


If necessary, you can even wrap things like "emacsclient.exe" in double quotes, and it still works.

Edited by norswap on
okay i got it working now, but it still opens a new windows every time i call it via terminal instead of reopening the running instance of emacs(if it has one?) and upon closing i believe its closing everything even the server? because i don't see any active process

Edited by Rafael Grossi on
Closing the window does indeed close the server on Windows (maybe there's a way to avoid that; but it's fine for me).

As for the other issue, I don't know. Did you remember put the "-f" part back in? Did you put the (server-start) in the init-file?

If the server is running, you should be able to type:

M-: (server-running-p) enter

and it should report "t"
(note that M-: stands for "ALT - colon")
yea i did put (server-start) .. no idea why it wasn't working but i've found a "fix"? i believe..
since when i run with

1
2
@"C:\Program Files\Emacs\bin\emacsclientw.exe" -na 
"C:\Program Files\Emacs\bin\runemacs.exe" %1"


seems to be working just fine (at least for now)

i'll see if i can get emacs to minimize to tray somehow? so it starts upon windows startup and keeps running as background

thanks for the help guys, sorry for the trouble :blush: