Skip to content

Automatically download PHP documentation? #288

@phil-s

Description

@phil-s

I'm just dropping this in here as food for thought. The following is the code I wrote to ensure that all of my dev environments will have access to local PHP docs inside Emacs via the eww browser, without me needed to fetch them manually.

It would be pretty nice if one could configure php-mode to do something similar.

;; Find documentation (locally or online).
(define-key php-mode-map (kbd "<f1>") 'php-search-documentation)
(when (fboundp 'eww-browse-url)
  (setq php-search-documentation-browser-function 'eww-browse-url))

;; Locate local documentation.
(let ((expected "/usr/local/share/php/php-chunked-xhtml"))
  (if (file-directory-p expected)
      (setq php-manual-path expected)
    (setq expected (expand-file-name "~/php/php-chunked-xhtml"))
    (if (file-directory-p expected)
        (setq php-manual-path expected)
      (message "PHP manual not found. Attempting download.")
      ;; Download and untar
      (let ((download-directory (file-name-directory expected))
            (url "http://php.net/get/php_manual_en.tar.gz/from/this/mirror")
            (file "php_manual_en.tar.gz"))
        (make-directory download-directory t)
        (shell-command
         (apply 'format
                "cd %s && wget -q %s -O %s && tar -xf %s && rm %s"
                (mapcar 'shell-quote-argument
                        (list download-directory url file file file)))))
      ;; Check the result
      (if (file-directory-p expected)
          (setq php-manual-path expected)
        (message "Failed to download PHP manual.")))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions