From f99468a135f2f11a3d64b274b014e66fd2899c98 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 6 Feb 2017 00:13:51 -0500 Subject: [PATCH] Move __DIR__/__FILE__ vars/defuns into core-lib --- core/core-lib.el | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/core/core-lib.el b/core/core-lib.el index dd6184694..c4397d64d 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -1,13 +1,36 @@ ;;; core-lib.el -(defvar +evil-leader) -(defvar +evil-localleader) - (require 'dash) (require 'f) (require 's) (eval-when-compile (require 'cl-lib)) + +(defvar +evil-leader) +(defvar +evil-localleader) + +(defvar __DIR__ nil "The directory of the currently loaded file (set by `load!')") +(defvar __FILE__ nil "The full path of the currently loaded file (set by `load!')") + +(defun __DIR__ () + "Get the full path to the current file's parent folder." + (or __DIR__ + (and load-file-name (f-dirname load-file-name)) + (and buffer-file-name (f-dirname buffer-file-name)) + default-directory + (and (bound-and-true-p byte-compile-current-file) + (f-dirname byte-compile-current-file)) + (error "__DIR__ is unset"))) + +(defun __FILE__ () + "Get the full path to the current file." + (or __FILE__ + load-file-name + buffer-file-name + (and (bound-and-true-p byte-compile-current-file) + byte-compile-current-file) + (error "__FILE__ is unset"))) + (package! anaphora :commands (awhen aif acond awhile))