Commit 62180af73822

Vincent Demeester <vincent@sbr.pm>
2017-05-13 16:16:48
Trying emacs-direnv out ๐Ÿ‰
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent def2072
.emacs.d/elpa/direnv-20170501.218/direnv-autoloads.el
@@ -0,0 +1,55 @@
+;;; direnv-autoloads.el --- automatically extracted autoloads
+;;
+;;; Code:
+(add-to-list 'load-path (directory-file-name (or (file-name-directory #$) (car load-path))))
+
+;;;### (autoloads nil "direnv" "direnv.el" (22807 4892 255909 159000))
+;;; Generated autoloads from direnv.el
+
+(autoload 'direnv-update-environment "direnv" "\
+Update the environment for FILENAME.
+
+\(fn &optional FILENAME)" t nil)
+
+(autoload 'direnv-edit "direnv" "\
+Edit the .envrc associated with the current directory.
+
+\(fn)" t nil)
+
+(defvar direnv-mode nil "\
+Non-nil if Direnv mode is enabled.
+See the `direnv-mode' command
+for a description of this minor mode.
+Setting this variable directly does not take effect;
+either customize it (see the info node `Easy Customization')
+or call the function `direnv-mode'.")
+
+(custom-autoload 'direnv-mode "direnv" nil)
+
+(autoload 'direnv-mode "direnv" "\
+Global minor mode to automatically update the environment using direnv.
+
+When this mode is active, the environment inside Emacs will be
+continuously updated to match the direnv environment for the currently
+visited (local) file.
+
+\(fn &optional ARG)" t nil)
+
+(autoload 'direnv-envrc-mode "direnv" "\
+Major mode for .envrc files as used by direnv.
+
+Since .envrc files are shell scripts, this mode inherits from sh-mode.
+\\{direnv-envrc-mode-map}
+
+\(fn)" t nil)
+
+(add-to-list 'auto-mode-alist '("\\.envrc\\'" . direnv-envrc-mode))
+
+;;;***
+
+;; Local Variables:
+;; version-control: never
+;; no-byte-compile: t
+;; no-update-autoloads: t
+;; End:
+;;; direnv-autoloads.el ends here
.emacs.d/elpa/direnv-20170501.218/direnv-pkg.el
@@ -0,0 +1,2 @@
+;;; -*- no-byte-compile: t -*-
+(define-package "direnv" "20170501.218" "direnv support for emacs" '((emacs "24.4") (dash "2.13.0") (with-editor "2.5.10")) :commit "2cdf87ea96f9a08dee98762b18b5f8a5198ecf63" :url "https://github.com/wbolster/emacs-direnv" :keywords '("direnv" "environment"))
.emacs.d/elpa/direnv-20170501.218/direnv.el
@@ -0,0 +1,212 @@
+;;; direnv.el --- direnv support for emacs
+
+;; Author: Wouter Bolsterlee <wouter@bolsterl.ee>
+;; Version: 1.2.0
+;; Package-Version: 20170501.218
+;; Package-Requires: ((emacs "24.4") (dash "2.13.0") (with-editor "2.5.10"))
+;; Keywords: direnv, environment
+;; URL: https://github.com/wbolster/emacs-direnv
+;;
+;; This file is not part of GNU Emacs.
+
+;;; Commentary:
+
+;; This package provides direnv integration for Emacs.
+;; See the README for more information.
+
+;;; Code:
+
+(require 'dash)
+(require 'json)
+(require 'subr-x)
+(require 'with-editor)
+
+(defgroup direnv nil
+  "direnv integration for emacs"
+  :group 'environment
+  :prefix "direnv-")
+
+(defun direnv--detect ()
+  "Detect the direnv executable."
+  (executable-find "direnv"))
+
+(defvar direnv--output-buffer-name " *direnv*"
+  "Name of the hidden buffer used for direnv interaction.")
+
+(defvar direnv--installed (direnv--detect)
+  "Whether direnv is installed.")
+
+(defvar direnv--active-directory nil
+  "Name of the directory for which direnv has most recently ran.")
+
+(defcustom direnv-always-show-summary nil
+  "Whether to show a summary message of environment changes on every change.
+
+When nil, a summary is only shown when direnv-update-environment is called
+interactively."
+  :group 'direnv
+  :type 'boolean)
+
+(defcustom direnv-show-paths-in-summary t
+  "Whether to show directory paths in the summary message."
+  :group 'direnv
+  :type 'boolean)
+
+(defcustom direnv-use-faces-in-summary t
+  "Whether to use custom font faces in the summary message.
+
+When enabled, the summary message uses custom font faces strings
+for added, changed, and removed environment variables, which
+usually results in coloured output."
+  :group 'direnv
+  :type 'boolean)
+
+(defun direnv--export (directory)
+  "Call direnv for DIRECTORY and return the parsed result."
+  (unless direnv--installed
+    (setq direnv--installed (direnv--detect)))
+  (unless direnv--installed
+    (user-error "Could not find the direnv executable. Is exec-path correct?"))
+  (with-current-buffer (get-buffer-create direnv--output-buffer-name)
+    (erase-buffer)
+    (let* ((default-directory directory)
+           (exit-code (call-process "direnv" nil '(t t) nil "export" "json")))
+      (unless (zerop exit-code)
+        (display-buffer (current-buffer))
+        (error "Error running direnv: exit code %s; output is in buffer '%s'"
+               exit-code direnv--output-buffer-name))
+      (unless (zerop (buffer-size))
+        (goto-char (point-max))
+        (re-search-backward "^{")
+        (let ((json-key-type 'string))
+          (json-read-object))))))
+
+(defun direnv--enable ()
+  "Enable direnv mode."
+  (add-hook 'post-command-hook #'direnv--maybe-update-environment)
+  (direnv--maybe-update-environment))
+
+(defun direnv--disable ()
+  "Disable direnv mode."
+  (remove-hook 'post-command-hook #'direnv--maybe-update-environment))
+
+(defun direnv--maybe-update-environment ()
+  "Maybe update the environment."
+  (with-current-buffer (window-buffer)
+    (let* ((filename (buffer-file-name (current-buffer))))
+      (when (and filename
+                 (not (string-equal direnv--active-directory (file-name-directory filename)))
+                 (not (file-remote-p filename)))
+        (direnv-update-environment filename)))))
+
+(defun direnv--maybe-enable-with-editor-mode ()
+  "Enable with-editor-mode when run via direnv-edit."
+  ;; This is a dirty hack. See https://github.com/magit/with-editor/issues/23
+  (run-at-time
+   1 nil
+   (lambda ()
+     (with-current-buffer (window-buffer)
+       (when server-buffer-clients
+         (with-editor-mode))))))
+
+(defun direnv--summarise-changes (items)
+  "Create a summary string for ITEMS."
+  (string-join
+   (--map
+    (let* ((name (car it))
+           (state (cdr it))
+           (face)
+           (prefix))
+      (pcase state
+        ('added   (setq prefix "+" face 'diff-added))
+        ('changed (setq prefix "~" face 'diff-changed))
+        ('removed (setq prefix "-" face 'diff-removed)))
+      (propertize (concat prefix name) 'face face))
+    (--sort
+     (string-lessp (symbol-name (cdr it)) (symbol-name (cdr other)))
+     (--map
+      (cons (car it)
+            (if (cdr it) (if (getenv (car it)) 'changed 'added) 'removed))
+      (--sort
+       (string-lessp (car it) (car other))
+       (--remove (string-prefix-p "DIRENV_" (car it)) items)))))
+   " "))
+
+(defun direnv--show-summary (items old-directory new-directory)
+  "Show a summary message for ITEMS.
+
+OLD-DIRECTORY and NEW-DIRECTORY are the directories before and afther
+the environment changes."
+  (let ((summary (direnv--summarise-changes items))
+        (paths (format
+                " (%s)"
+                (if (and old-directory (string-equal old-directory new-directory))
+                    new-directory
+                  (format "from %s to %s" (or old-directory "(none)") new-directory)))))
+    (when (string-empty-p summary)
+      (setq summary "no changes"))
+    (unless direnv-show-paths-in-summary
+      (setq paths ""))
+    (unless direnv-use-faces-in-summary
+      (setq summary (substring-no-properties summary)))
+    (message "direnv: %s%s" summary paths)))
+
+;;;###autoload
+(defun direnv-update-environment (&optional filename)
+  "Update the environment for FILENAME."
+  (interactive)
+  (let ((filename (or filename buffer-file-name))
+        (old-directory direnv--active-directory))
+    (unless filename
+      (user-error "Buffer is not visiting a file"))
+    (when (file-remote-p filename)
+      (user-error "Cannot use direnv for remote files"))
+    (setq direnv--active-directory (file-name-directory filename))
+    (let ((items (direnv--export direnv--active-directory)))
+      (when (or direnv-always-show-summary (called-interactively-p 'interactive))
+        (direnv--show-summary items old-directory direnv--active-directory))
+      (dolist (pair items)
+        (let ((name (car pair))
+              (value (cdr pair)))
+          (setenv name value)
+          (when (string-equal name "PATH")
+            (setq exec-path (append (parse-colon-path value) (list exec-directory)))))))))
+
+;;;###autoload
+(defun direnv-edit ()
+  "Edit the .envrc associated with the current directory."
+  (interactive)
+  (let ((display-buffer-alist
+         (cons (cons "\\*Async Shell Command\\*.*" (cons #'display-buffer-no-window nil))
+               display-buffer-alist)))
+    (with-editor-async-shell-command "direnv edit" nil nil))
+  (direnv-update-environment))
+
+;;;###autoload
+(define-minor-mode direnv-mode
+  "Global minor mode to automatically update the environment using direnv.
+
+When this mode is active, the environment inside Emacs will be
+continuously updated to match the direnv environment for the currently
+visited (local) file."
+  :global t
+  (if direnv-mode
+      (direnv--enable)
+    (direnv--disable)))
+
+;;;###autoload
+(define-derived-mode direnv-envrc-mode
+  sh-mode "envrc"
+  "Major mode for .envrc files as used by direnv.
+
+Since .envrc files are shell scripts, this mode inherits from sh-mode.
+\\{direnv-envrc-mode-map}")
+
+(add-hook 'direnv-envrc-mode-hook #'direnv--maybe-enable-with-editor-mode)
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.envrc\\'" . direnv-envrc-mode))
+
+(provide 'direnv)
+
+;;; direnv.el ends here
.emacs.d/elpa/direnv-20170501.218/direnv.elc
Binary file
.emacs.d/emacs.el
@@ -1102,8 +1102,8 @@ This can be 0 for immediate, or a floating point value.")
     (while (re-search-forward "\* \\(DONE\\|CANCELED\\) " nil t)
    (if (save-restriction
             (save-excursion
-   	   (org-narrow-to-subtree)
-   	   (search-forward ":LOGBOOK:" nil t)))
+      	(org-narrow-to-subtree)
+      	(search-forward ":LOGBOOK:" nil t)))
           (forward-line)
         (org-archive-subtree)
         (goto-char (line-beginning-position))))))
@@ -1975,6 +1975,11 @@ PRIORITY may be one of the characters ?A, ?B, or ?C."
 (use-package nix-sandbox
   :ensure t)
 
+(use-package direnv
+  :ensure t
+  :init
+  (direnv-mode))
+
 ;; The folder is by default $HOME/.emacs.d/provided
 (setq user-emacs-provided-directory (concat user-emacs-directory "provided/"))
 ;; Regexp to find org files in the folder
.emacs.d/emacs.org
@@ -3239,6 +3239,19 @@
         :ensure t)
     #+END_SRC
 
+*** =direnv=
+
+    Although it's not completely relevant to =nix= (as it can be used
+    on other systems), let's try to integrate =direnv= with emacs.
+
+    #+BEGIN_SRC emacs-lisp
+      (use-package direnv
+        :ensure t)
+    #+END_SRC
+    
+    Not automatically enabling it for now as it might be a little bit
+    too resource hungry (and might need network).
+
 * Provided configuration
 
   I'm managing my configurations using [[https://github.com/RichiH/vcsh][vcsh]] and [[http://myrepos.branchable.com/][myrepos]], like [[https://github.com/vdemeester/vcsh-home#how-it-is-supposed-to-work][that]]. I have a lot