From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: open in browser Date: Fri, 27 Jan 2017 10:16:41 -0800 Message-ID: References: <877f5ghd5x.fsf@kaffanke.at> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1485541057 15154 195.159.176.226 (27 Jan 2017 18:17:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 27 Jan 2017 18:17:37 +0000 (UTC) Cc: Martin To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jan 27 19:17:33 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXB5W-0003Ly-JY for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jan 2017 19:17:30 +0100 Original-Received: from localhost ([::1]:47252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXB5b-0006pI-Li for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jan 2017 13:17:35 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXB58-0006oc-6X for help-gnu-emacs@gnu.org; Fri, 27 Jan 2017 13:17:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXB57-0000vt-7q for help-gnu-emacs@gnu.org; Fri, 27 Jan 2017 13:17:06 -0500 Original-Received: from mail-yw0-x22b.google.com ([2607:f8b0:4002:c05::22b]:36325) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cXB57-0000vV-36 for help-gnu-emacs@gnu.org; Fri, 27 Jan 2017 13:17:05 -0500 Original-Received: by mail-yw0-x22b.google.com with SMTP id v200so22392886ywc.3 for ; Fri, 27 Jan 2017 10:17:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=srd4Qz66Ej5S9oY9GM7OVjlxLmsPrISbRGlu1GdEIPk=; b=JvQZeSGfNcjBLrF2n75+tXpbpk4Hjt8xaoUYmuy1Q87vnqWDx4sZzplIYvi/XltgI3 MA1Nh5NgAb9n2TEbysJjSqdezBM36i6jNx5tDBP+vf68O6cHnvEY+069Sl2rBscVe3lu IsdzHX+LRCbforQFRBpKXngJpr8es8RSPQhP/EterGQ5fb2Eycl9jCxkigKSYRmBawGR K21r2eYSFAmprIRlOw7r+ajAezJR7y+5obUGwj7+uPqEEnlocYJIoeYvlxjahgAF91Uo ZMW/tGGuI4asZA9/gsfcqk+8WcL0G1AyhkhxqDRf6I2PzkvjE/xm9KD/kysQWLT9MCcd BZ+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=srd4Qz66Ej5S9oY9GM7OVjlxLmsPrISbRGlu1GdEIPk=; b=px2zM3LZRCy/Ubjck6sVDNypXhR8ni+JFUz8cMGVZUaakijfLwvRNJ97g0HGFwUg68 me6jxIir6tLN3wSaH6Pjfnct+KwSGHPW772fmR8iUeEgpUY7cOP0A/bvGM54PE0mBSuj JKn014Ze8bFwZ3MhlMTh0QmRGisDFTiaUz3kRQq9OzMcAGw8w/zvf7y2m0a7vLpsWScU jUg64J0w81aje/S4Fb6GvzNVkf5QhiAC/xJSUJ3s4ZJS+G+M6C8dFQdf9WEcSPAs4Z4i sagj3dE16ya+UR1onRPVMcpom3qQ2YYd6h7hO5nvGqto3Q/Zd0+PBJfkRmJT5nHsWAm7 AZzQ== X-Gm-Message-State: AIkVDXKENlw4Th2UrZLSayI7ZnG5sdCPSwL3L4/9MSJpd6TNXgkGVLWtkDHRfIMQQ4Kl+2Yy81HVk1DfK3DBwQ== X-Received: by 10.233.237.136 with SMTP id c130mr10110528qkg.160.1485541022575; Fri, 27 Jan 2017 10:17:02 -0800 (PST) Original-Received: by 10.237.41.2 with HTTP; Fri, 27 Jan 2017 10:16:41 -0800 (PST) In-Reply-To: <877f5ghd5x.fsf@kaffanke.at> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c05::22b X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112175 Archived-At: Martin wrote: > Hi there, > > at the moment I'm using > > ;; (setq browse-url-browser-function 'browse-url-chromium) > (setq browse-url-browser-function 'browse-url-firefox) > > to determine which browser to use within emacs. For some reasons I > switch between firefox and chromium, and now I wonder if I could get > emacs to use the browser I'm using at the moment. But I don't really > know where to start maybe you can help me. > > I'm using arch linux with emacs 25.1.1 here. > > If firefox is running (we can see it in proc maybe get it with ps) I > want emacs to open links in firefox and if chromium is running I want > emacs to open links in chromium. And if both are running i would > prefer chromium. > > How could a function for browse-url-browser-function look like for that > purpose? Not really tested, but maybe something along these lines would work: (require 'seq) (defun find-current-browser () (let ((regexp "\\`\\(chrome\\|chromium\\|firefox\\)\\(\\.exe\\)?\\'")) (seq-some (lambda (pid) (let ((comm (alist-get 'comm (process-attributes pid)))) (when (string-match regexp comm) (intern (match-string 1 comm))))) (list-system-processes)))) (defun browse-url-dynamic-browser-function (&rest args) (apply (pcase (find-current-browser) (`chrome #'browse-url-chrome) (`chromium #'browse-url-chromium) (`firefox #'browse-url-firefox) (_ #'browse-url-default-browser)) args)) (setq browse-url-browser-function #'browse-url-dynamic-browser-function) Hope that helps John