I want to call some functions when I run emacsclient in a terminal emulator. The code I have is working when Emacs is running in a text terminal. When I start Emacs in graphical mode and run emacsclient -t
in the terminal, the functions do not start, so I cannot use the mouse in the terminal emulator.
Here is the code in question:
(defun my-terminal-config (&optional frame) "Establish settings for the current terminal." (message (format "%s" window-system)) ;; "ns" (Mac OS X) when Emacs is started graphically (message (format "%s" (display-graphic-p))) ;; nil when Emacs is started graphically (unless (display-graphic-p) ;; enable mouse reporting for terminal emulators (xterm-mouse-mode 1) (global-set-key [mouse-4] '(lambda () (interactive) (scroll-down 1))) (global-set-key [mouse-5] '(lambda () (interactive) (scroll-up 1))))) (add-hook 'after-make-frame-functions 'my-terminal-config)
This is a strange situation. Emacsclient connects to the server and creates a new frame, but since the server runs in a graphical environment, it reports that the window system is "ns", whereas in a terminal environment it will be zero. So when I run emacsclient -t
terminal, functions enable the mouse messages will not start. After starting emacsclient, if I create a new frame with Cx 5 2
, then the functions for including mouse messages will be enabled, because the window system will be zero in this frame.
It seems that when mixing frames between terminals and window systems, the value of window-system
will always match the value of the Emacs server.
Is there a way that I can run Emacs graphically and emacsclient in text mode and run mouse functions? In other words, is it possible to detect that the frame being created is in a graphical or textual environment?
Maybe I should just run these functions when creating the frame, regardless of the value of the window-system
?
source share