]> git.eshelyaron.com Git - emacs.git/commitdiff
Move optional jumping functionality to its own module
authorJohn Wiegley <johnw@newartisans.com>
Sun, 3 Dec 2017 21:11:40 +0000 (13:11 -0800)
committerJohn Wiegley <johnw@newartisans.com>
Sun, 3 Dec 2017 21:13:30 +0000 (13:13 -0800)
lisp/use-package/use-package.el
up-core.el
up-jump.el [new file with mode: 0644]

index 6169732614dd29a66f90850cded3ec51a64dc0ef..ec459ab16622adf423515e03cc8606f1325f1054 100644 (file)
 ;;; Code:
 
 (require 'up-core)
+
 (require 'up-ensure)
 (require 'up-diminish)
 (require 'up-delight)
 
+(autoload #'use-package-jump-to-package-form "up-jump" nil t)
+
 (provide 'use-package)
 
 ;; Local Variables:
index d11c2d7106fb99b767cca4e61d70b269525d5d2d..81cae6e177b7f507470ad976b3c2c720ae9ff397 100644 (file)
@@ -1426,47 +1426,6 @@ this file.  Usage:
 
 (put 'use-package 'lisp-indent-function 'defun)
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;
-;;; Jump to declaration
-;;
-
-(defun use-package-find-require (package)
-  "Find file that required PACKAGE by searching `load-history'.
-Returns an absolute file path or nil if none is found."
-  (catch 'suspect
-    (dolist (filespec load-history)
-      (dolist (entry (cdr filespec))
-        (when (equal entry (cons 'require package))
-          (throw 'suspect (car filespec)))))))
-
-(defun use-package-jump-to-package-form (package)
-  "Attempt to find and jump to the `use-package' form that loaded
-PACKAGE. This will only find the form if that form actually
-required PACKAGE. If PACKAGE was previously required then this
-function will jump to the file that originally required PACKAGE
-instead."
-  (interactive (list (completing-read "Package: " features)))
-  (let* ((package (if (stringp package) (intern package) package))
-         (requiring-file (use-package-find-require package))
-         file location)
-    (if (null requiring-file)
-        (user-error "Can't find file requiring file; may have been autoloaded")
-      (setq file (if (string= (file-name-extension requiring-file) "elc")
-                     (concat (file-name-sans-extension requiring-file) ".el")
-                   requiring-file))
-      (when (file-exists-p file)
-        (find-file-other-window file)
-        (save-excursion
-          (goto-char (point-min))
-          (setq location
-                (re-search-forward
-                 (format (eval use-package-form-regexp-eval) package) nil t)))
-        (if (null location)
-            (message "No use-package form found.")
-          (goto-char location)
-          (beginning-of-line))))))
-
 (provide 'up-core)
 
 ;; Local Variables:
diff --git a/up-jump.el b/up-jump.el
new file mode 100644 (file)
index 0000000..721c17c
--- /dev/null
@@ -0,0 +1,77 @@
+;;; up-jump.el --- Attempt to jump to a use-package declaration
+
+;; Copyright (C) 2012-2017 John Wiegley
+
+;; Author: John Wiegley <johnw@newartisans.com>
+;; Maintainer: John Wiegley <johnw@newartisans.com>
+;; Created: 17 Jun 2012
+;; Modified: 3 Dec 2017
+;; Version: 1.0
+;; Package-Requires: ((emacs "24.3") (use-package "2.4"))
+;; Keywords: dotemacs startup speed config package
+;; URL: https://github.com/jwiegley/use-package
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 3, or (at
+;; your option) any later version.
+
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; Provides the command `M-x use-package-jump-to-package-form', however it
+;; only works if the package being jumped to was required during
+;; initialization. If it was delay-loaded, it will not work. Improvements are
+;; needed.
+
+;;; Code:
+
+(require 'up-core)
+
+(defun use-package-find-require (package)
+  "Find file that required PACKAGE by searching `load-history'.
+Returns an absolute file path or nil if none is found."
+  (catch 'suspect
+    (dolist (filespec load-history)
+      (dolist (entry (cdr filespec))
+        (when (equal entry (cons 'require package))
+          (throw 'suspect (car filespec)))))))
+
+;;;###autoload
+(defun use-package-jump-to-package-form (package)
+  "Attempt to find and jump to the `use-package' form that loaded
+PACKAGE. This will only find the form if that form actually
+required PACKAGE. If PACKAGE was previously required then this
+function will jump to the file that originally required PACKAGE
+instead."
+  (interactive (list (completing-read "Package: " features)))
+  (let* ((package (if (stringp package) (intern package) package))
+         (requiring-file (use-package-find-require package))
+         file location)
+    (if (null requiring-file)
+        (user-error "Can't find file requiring file; may have been autoloaded")
+      (setq file (if (string= (file-name-extension requiring-file) "elc")
+                     (concat (file-name-sans-extension requiring-file) ".el")
+                   requiring-file))
+      (when (file-exists-p file)
+        (find-file-other-window file)
+        (save-excursion
+          (goto-char (point-min))
+          (setq location
+                (re-search-forward
+                 (format (eval use-package-form-regexp-eval) package) nil t)))
+        (if (null location)
+            (message "No use-package form found.")
+          (goto-char location)
+          (beginning-of-line))))))
+
+(provide 'up-jump)