Descrizione
Il comportamento predefinito quando si richiama emacsclient è un po 'conservativo. Guarda questo commento da
emacsclient.c :
/* Unless we are certain we don't want to occupy the tty, send our
tty information to Emacs. For example, in daemon mode Emacs may
need to occupy this tty if no other frame is available. */
Dalla descrizione e dai commenti, sembra che tu stia cercando di avviare il server Emacs su richiesta mentre usi anche la -nbandiera. Il commento "ad esempio" qui è perché emacsclient -n -a '' FILEnon soddisfa ciò che stai cercando quando nessun server è in esecuzione.
- La
-a ''logica avvia un demone.
- Quindi gli
emacsclientdice di creare un nuovo frame terminale, perché è quello predefinito a meno che non stiate valutando elisp.
- La
-nlogica uccide immediatamente quel nuovo frame terminale.
Se potessi modificare il passaggio 2 per creare un nuovo frame grafico per impostazione predefinita,
emacsclient -n -a '' FILEfarebbe quello che vuoi.
Soluzione Elisp
È possibile fare in modo che Emacs crei un nuovo frame grafico per impostazione predefinita se si consiglia la funzione in questo server-process-filtermodo:
(defadvice server-process-filter (before prefer-graphical activate)
;; STRING is a sequence of commands sent from emacsclient to the server.
(when (and
;; Check that we're editing a file, as opposed to evaluating elisp.
(string-match "-file" string)
;; Check that there are no frames beyond the Emacs daemon's terminal.
(daemonp)
(null (cdr (frame-list)))
(eq (selected-frame) terminal-frame)
;; Check that we have a graphical display.
;; `display-graphic-p' doesn't work here.
(getenv "DISPLAY"))
(setq string (concat
;; STRING must be all one line, but comes to us
;; newline-terminated. Strip off the trailing newline.
(replace-regexp-in-string "\n$" "" string)
;; Add the commands to create a graphical frame.
"-window-system "
"-display " (getenv "DISPLAY")
;; Add back the newline.
"\n"))))
Inseriscilo nel file init, quindi, come detto, emacsclient -n -a '' FILEe Bob è tuo zio.
Confronta con la soluzione Shell
Da un lato, posso indicare alcuni vantaggi nell'uso di questo approccio defadvice rispetto all'uso dello
script suggerito da Archenoth
#!/bin/bash
emacs --eval '(server-start)' $* &
come editor alternativo. Con il defadvice:
save-buffers-kill-terminal( C-x C-cper impostazione predefinita) si comporta in modo coerente in tutti i frame. Non uccide mai il processo Emacs, perché ogni frame è sempre un frame client.
- La cornice terminale del demone si blocca. Comandi come
find-grepquelli shell out verso processi esterni si comportano meglio quando c'è il terminale stupido. Almeno, avverto meno mal di testa correlati alla fuga di shell.
D'altra parte ... sì.
- Lo script della shell è meravigliosamente semplice.
- Consigliare il protocollo di comunicazione di Emacs non lo è.
Conclusione
Forse c'è un compromesso? Questo è il massimo che ho potuto inventare. Lo imposta come $ EDITOR.
#!/bin/sh
emacsclient -e "(frames-on-display-list \"${DISPLAY}\")" 1>/dev/null 2>/dev/null
if [ "$?" = "1" ]; then
emacsclient -c -n -a "" "$@"
else
emacsclient -n "$@"
fi
-a ''opzione "avvia il demone Emacs e riprova emacsclient"?