Skip to content

Instantly share code, notes, and snippets.

@davazp
Created September 18, 2015 13:06
Show Gist options
  • Save davazp/c56940cafe1e23c77b0c to your computer and use it in GitHub Desktop.
Save davazp/c56940cafe1e23c77b0c to your computer and use it in GitHub Desktop.
Find node module at point
;;; Try to find the string at point as a NodeJS module
(require 'ffap)
(defun ffap-nodejs-module (name)
(unless (or (string-prefix-p "/" name)
(string-prefix-p "./" name)
(string-prefix-p "../" name))
(let ((base (locate-dominating-file
default-directory
(lambda (dir)
(let ((filename (concat dir "node_modules/" name)))
(and (file-exists-p filename)
filename))))))
(and base (concat base "node_modules/" name)))))
(add-to-list 'ffap-alist '(js-mode . ffap-nodejs-module) t)
(add-to-list 'ffap-alist '(js2-mode . ffap-nodejs-module) t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment