Created
September 18, 2015 13:06
-
-
Save davazp/c56940cafe1e23c77b0c to your computer and use it in GitHub Desktop.
Find node module at point
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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