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

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

Re: Help with PHP setup


From: Jean-Christophe Helary
Subject: Re: Help with PHP setup
Date: Mon, 23 Jul 2018 00:53:08 +0900


> On Jul 23, 2018, at 0:44, Jean-Christophe Helary <brandelune@gmail.com> wrote:
> 
>> On Jul 23, 2018, at 0:36, Noam Postavsky <npostavs@gmail.com> wrote:
>> 
>> On 22 July 2018 at 11:20, Jean-Christophe Helary <brandelune@gmail.com> 
>> wrote:
>> 
>>>    (setq myTestCommand (concat "open " myServerRoot myFile)) ;; this "open 
>>> " command only works on macOS... I don't know equivalents on Linux.
>> 
>> By the way, xdg-open is approximately equivalent on many GNU/Linux
>> distros; you might also consider using Emacs'
>> browse-url-default-browser function, which tries looking for other
>> browsers if the former fails.
> 
> Nice hint :) Thank you !

So, I guess I have something working for my case now:

(defun myLocalhostTest ()
  "saves and opens the file opened in the current buffer into localhost"
  (interactive)
  (global-set-key (kbd "s-r") 'myLocalhostTest)
  (save-excursion
    (save-buffer)
    (setq myLocalRoot "/Applications/MAMP/htdocs/")
    (setq myServerRoot "http://localhost:8888/";)
    (setq myFile (substring (buffer-file-name) (length myLocalRoot)))
    ;; the 2 lines below are useful for some WP files, but I'm not sure yet how 
the whole thing works
    (if (equal (car (cdr (split-string myFile "/"))) "wp-content")
        (setq myFile (concat (car (split-string myFile "/")) "/" 
(file-name-nondirectory (buffer-file-name)))))
    ;; end of the WP special case
    (setq myURL (concat myServerRoot myFile))
    (browse-url-default-browser myURL)))

That works for all the php/html files I have, at least those that are in 
similar relative position vs the localhost root.

I'm sure there are better ways to achieve a similar result, but that's good 
enough for now :) Thank you all.


Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune





reply via email to

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