Add some standard places to PATH if they are not set by login script.
Rearrange the order of paths so system's are first, user's are last.
For Cygwin this helps with Cygwin's paths to be situated before
"C:/Windows" (Emacs is not started from a login shell on Windows!).
(require 'company)
(require 'cl-lib)
(require 'web-mode)
(unless (fboundp 'web-mode-language-at-pos)
(defun web-mode-language-at-pos (&optional pos)
(plist-get (web-mode-point-context (or pos (point))) :language)))
(defvar company-dom--document-methods
'("getElementById" "getElementsByClassName" "createElement" "createElementNS" "createEvent"))
(defvar company-dom--window-methods
'("console" "document" "location"))
(defun company-dom--prefix ()
(when (looking-back "\\<\\w+\\(?:\\.?\\w+\\>\\|\\.\\)")
(match-string 0)))
(defun company-dom--candidates (prefix)
(cond
((string-match "^window\\.\\(.*\\)" prefix)
(mapcar
(lambda (str) (concat "window." str))
(all-completions (match-string 1) company-dom--window-methods)))
((string-match "^document\\.\\(.*\\)" prefix)
(mapcar
(lambda (str) (concat "document." str))
(all-completions (match-string 1) company-dom--document-methods)))
(t
(all-completions prefix '("document" "window")))
))
(defun company-web (command &optional arg &rest ignored)
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-web))
(prefix
(pcase (plist-get (web-mode-point-context (point)) :language)
("css" (company-css 'prefix))
("javascript" (company-dom--prefix))))
(candidates
(pcase (plist-get (web-mode-point-context (point)) :language)
("css" (company-css 'candidates arg))
("javascript" (company-dom--candidates arg))))
(meta (format "This value is named %s" arg))))
(defun company-web-register ()
(set (make-local-variable 'company-backends) '(company-web)))
(add-hook 'web-mode-hook #'company-web-register)
;; Debug company with M-x company-diag.