Emacs 23, OS X, multi-tty and emacsclient

How can I get emacs 23 to work in multi-tty mode on OS X?

I added (server-start)to my .emacs and found that the launch /Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n ~/myfile.txtwould open it in my emacs.app, but it did not bring emacs to the fore.

So how can I get emacs.app to come to the fore when I run emacsclient? (I considered writing a function that puts the current frame at the front each time a file is opened, or maybe write Applescript to perform a similar task that could be called simultaneously with emacsclient)

Is emacsclient in emacs.app the best to use? I suppose I will write an alias if this is the case, but it seems strange to use this and not something in / usr / local / bin

Does anyone have any other tips or examples of getting this work?

+5
source share
8 answers

AppleScript will be simple:

tell app "Emacs" to activate
+2
source

I have an alias from emacs to

open -a /Applications/Emacs.app "$@"

If you are annoyed by the fact that it opens a new frame (window) for each file - add

(setq ns-pop-up-frames nil)

to your .emacs and fixed.

+6
source

, , raise-frame :

(add-hook 'server-visit-hook 'call-raise-frame)
(defun call-raise-frame ()
  (raise-frame))

( Linux .)

+5

" ". emacs, . emacs , emacs , . "select-frame-set-input-focus" .

:

/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n ~/myfile.txt \
    --eval '(select-frame-set-input-focus (nth 0 (frame-list)))'

emacs, , "^ X ^ C", . script:

#!/bin/bash
/Applications/Emacs.app/Contents/MacOS/Emacs \
    --eval '(select-frame-set-input-focus (nth 0 (frame-list)))' \
    "$@"
+4

- .emacs, , :

(if (file-exists-p
 (concat (getenv "TMPDIR") "emacs"
         (number-to-string
          (user-real-uid)) "/server"))
nil (server-start))

.zshrc, ec :

# I use the Emacs package from emacsformacosx.com
alias emacs='open -a emacs'
alias emacsclient='/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'
alias ec='emacsclient -a /Applications/Emacs.app/Contents/MacOS/Emacs'
export EDITOR='ec'
+2

, Singletoned: .emacs :

;;;
;;; Run in server-mode so other sessions can connet
;;;
(defun call-raise-frame ()
   (raise-frame))
(defun end-server-edit ()
   (shell-command "osascript -e \"tell application \\\"System Events\\\" to keystroke tab using command down\""))
(add-hook 'server-visit-hook 'call-raise-frame)
(add-hook 'server-done-hook 'end-server-edit)
(server-start)

:

alias e='emacsclient'      # edit
alias enw='emacsclient -n' #edit (no wait)

, CocoaEmacs . "inline" , e, emacs, .

+1

.emacs

(defun ns-raise-emacs ()
  (ns-do-applescript "tell application \"Emacs\" to activate"))

, :

emacsclient -e '(ns-raise-emacs)'

, osascript. , ( ), osascript.

0

fwiw, :
1: script /usr/local/bin/emacs :

#!/usr/bin/bash
emacsclient -c --alternate-editor='/Applications/Emacs.app/Contents/MacOS/Emacs'  "$@" 2>/dev/null

2. : chmod + x/usr/local/bin/emacs

3. ~/.emacs :

(server-start)  

(defun ns-raise-emacs ()  
(ns-do-applescript "tell application \"Emacs\" to activate"))  

(ns-raise-emacs)  

(add-hook 'server-visit-hook 'raise-frame)  
;;(add-hook 'server-visit-hook 'ns-raise-emacs)

:

emacs script /usr/local/bin/emacs , emacs, emacsclient , Emacs (/Applications/Emacs. //MacOS/Emacs).

3 (ns-raise-emacs) , Emacs .

(add-hook 'server-visit-hook 'raise-frame) lies in the fact that subsequent frames appear in front of everything else.

Alternatively, if you prefer all Emacs frames to appear in front of everything else every time you call emacs from the command line, you can uncomment the line (add-hook 'server-visit-hook 'ns-raise-emacs).

0
source

All Articles