help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: check whether emacs session is running under local X server


From: Eric Hanchrow
Subject: Re: check whether emacs session is running under local X server
Date: Wed, 27 Sep 2006 15:39:09 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

>>>>> "Roland" == Roland Winkler <Roland.Winkler@physik.uni-erlangen.de> writes:

    Roland> In my .emacs I would like to distinguish between an emacs
    Roland> session running under the local X server and an emacs
    Roland> session running under a remote X server.  I expect that
    Roland> the $DISPLAY variable can do the job.  But I am not
    Roland> familiar with the details.  (Once upon a time I set
    Roland> $DISPLAY manually.  Nowadays I use ssh which handles
    Roland> $DISPLAY for me, but I do not understand the scheme it
    Roland> uses.)

I don't think there's a 100% foolproof way, but here's how I do it:

(Isn't this awful?)

(let ((x-running-locally
       (and
        (boundp 'window-system)
        (or (eq (assoc-default 'window-system (frame-parameters current-frame)) 
'x)
            (and (assq 'font (frame-parameters current-frame))
                 (assq 'display (frame-parameters current-frame))))
        (getenv "DISPLAY")

        (let ((display-data (split-string (getenv "DISPLAY") ":")))
          (if (= 1 (length display-data)) ; e.g. ("0")

              ;; e.g. ("offby1" "0")
              (setq display-data (cons (car (split-string (system-name) "\\.")) 
display-data))

            (let* ((display-host (nth 0 display-data))
                   (display-number (car (read-from-string (nth 1 
display-data)))))
              ;; display numbers >=10 imply we're using SSH from a remote
              ;; machine
              (and (< display-number 10)
                   ;; (string-equal (downcase (car (split-string display-host 
"\\.")))
                   ;;                           (downcase (car (split-string 
(system-name)"\\."))))
                   ))))))
      ))

-- 
When it comes to electronic voting, most liberals are just plain
old-fashioned nuts.
        -- Joe Andrew, former chairman of the Democratic National
           Committee





reply via email to

[Prev in Thread] Current Thread [Next in Thread]