about summary refs log tree commit diff
path: root/tools/emacs/init/functions.el
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-14T13·23+0000
committerVincent Ambo <tazjin@google.com>2019-12-14T13·23+0000
commitc490bbf4b3d57df111476f76f3a5c8ad2d04fa33 (patch)
tree10320810bb4048512a13ef99cca330298ed45abc /tools/emacs/init/functions.el
parent1f204f2891038bfced0b799837764495d351f1a5 (diff)
chore(emacs.d): Import several months of privately tracked changes r/141
These changes were made in a fork of my configuration that is not
publicly available and detailed history will not be included in this
public commit.
Diffstat (limited to 'tools/emacs/init/functions.el')
-rw-r--r--tools/emacs/init/functions.el130
1 files changed, 35 insertions, 95 deletions
diff --git a/tools/emacs/init/functions.el b/tools/emacs/init/functions.el
index 8b96a0e737df..e0bc496a538f 100644
--- a/tools/emacs/init/functions.el
+++ b/tools/emacs/init/functions.el
@@ -1,59 +1,4 @@
 (require 's)
-;; A few handy functions I use in init.el (or not, but they're nice to
-;; have)
-
-(defun custom-download-theme (url filename)
-  "Downloads a theme through HTTP and places it in ~/.emacs.d/themes"
-
-  ;; Ensure the directory exists
-  (unless (file-exists-p "~/.emacs.d/themes")
-    (make-directory "~/.emacs.d/themes"))
-
-  ;; Adds the themes folder to the theme load path (if not already
-  ;; there)
-  (unless (member "~/.emacs.d/themes" custom-theme-load-path)
-    (add-to-list 'custom-theme-load-path "~/.emacs.d/themes"))
-
-  ;; Download file if it doesn't exist.
-
-  (let ((file
-         (concat "~/.emacs.d/themes/" filename)))
-    (unless (file-exists-p file)
-      (url-copy-file url file))))
-
-(defun custom-download-script (url filename)
-  "Downloads an Elisp script, places it in ~/.emacs/other and then loads it"
-
-  ;; Ensure the directory exists
-  (unless (file-exists-p "~/.emacs.d/other")
-    (make-directory "~/.emacs.d/other"))
-
-  ;; Download file if it doesn't exist.
-  (let ((file
-         (concat "~/.emacs.d/other/" filename)))
-    (unless (file-exists-p file)
-      (url-copy-file url file))
-
-    (load file)))
-
-(defun keychain-password (account &optional keychain)
-  "Returns the password for the account, by default it's looked up in the Login.keychain but a
-   different keychain can be specified."
-  (let ((k (if keychain keychain "Login.keychain")))
-    (replace-regexp-in-string
-     "\n" ""
-     (shell-command-to-string (concat  "security find-generic-password -w -a "
-                                       account
-                                       " "
-                                       k)))))
-
-;; This clones a git repository to 'foldername in .emacs.d
-;; if there isn't already a folder with that name
-(defun custom-clone-git (url foldername)
-  "Clones a git repository to .emacs.d/foldername"
-  (let ((fullpath (concat "~/.emacs.d/" foldername)))
-    (unless (file-exists-p fullpath)
-      (async-shell-command (concat "git clone " url " " fullpath)))))
 
 (defun load-file-if-exists (filename)
   (if (file-exists-p filename)
@@ -70,7 +15,6 @@
           (goto-line target)))
     (setq-local display-line-numbers nil)))
 
-
 (defun untabify-buffer ()
   (interactive)
   (untabify (point-min) (point-max)))
@@ -105,11 +49,6 @@ Including indent-buffer, which should not be called automatically on save."
   (interactive)
   (eww "https://blog.fefe.de/"))
 
-;; Open this machines NixOS config
-(defun nix-config ()
-  (interactive)
-  (find-file "/etc/nixos/configuration.nix"))
-
 ;; Open the NixOS man page
 (defun nixos-man ()
   (interactive)
@@ -158,15 +97,23 @@ Including indent-buffer, which should not be called automatically on save."
    append lsdir into completions
    finally return (sort completions 'string-lessp)))
 
+(defvar external-command-flag-overrides
+  '(("google-chrome" . "--force-device-scale-factor=1.4"))
+
+  "This setting lets me add additional flags to specific commands
+  that are run interactively via `ivy-run-external-command'.")
+
 (defun run-external-command (cmd)
-    "Execute the specified command and notify the user when it
+  "Execute the specified command and notify the user when it
   finishes."
-    (message "Starting %s..." cmd)
-    (set-process-sentinel
-     (start-process-shell-command cmd nil cmd)
-     (lambda (process event)
-       (when (string= event "finished\n")
-         (message "%s process finished." process)))))
+    (let* ((extra-flags (cdr (assoc cmd external-command-flag-overrides)))
+           (cmd (if extra-flags (s-join " " (list cmd extra-flags)) cmd)))
+      (message "Starting %s..." cmd)
+      (set-process-sentinel
+       (start-process-shell-command cmd nil cmd)
+       (lambda (process event)
+         (when (string= event "finished\n")
+           (message "%s process finished." process))))))
 
 (defun ivy-run-external-command ()
   "Prompts the user with a list of all installed applications and
@@ -235,32 +182,25 @@ Including indent-buffer, which should not be called automatically on save."
   (inferior-erlang
    (format "nix-shell --command erl %s" (cdr (project-current)))))
 
-(defun intero-fix-ghci-panic ()
-  "Disable deferring of out of scope variable errors, which
-  triggers a bug in the interactive Emacs REPL printing a panic
-  under certain conditions."
-
-  (interactive)
-  (let* ((root (intero-project-root))
-         (package-name (intero-package-name))
-         (backend-buffer (intero-buffer 'backend))
-         (name (format "*intero:%s:%s:repl*"
-                       (file-name-nondirectory root)
-                       package-name))
-         (setting ":set -fno-defer-out-of-scope-variables\n"))
-    (when (get-buffer name)
-      (with-current-buffer (get-buffer name)
-        (goto-char (point-max))
-        (let ((process (get-buffer-process (current-buffer))))
-          (when process (process-send-string process setting)))))))
-
-;; Brute-force fix: Ensure the setting is injected every time the REPL
-;; is selected.
-;;
-;; Upstream issue: https://github.com/commercialhaskell/intero/issues/569
-(advice-add 'intero-repl :after (lambda (&rest r) (intero-fix-ghci-panic))
-            '((name . intero-panic-fix)))
-(advice-add 'intero-repl-load :after (lambda (&rest r) (intero-fix-ghci-panic))
-            '((name . intero-panic-fix)))
+(defun memespace-region ()
+  "Make a meme out of it."
+
+  (interactive)
+  (let* ((start (region-beginning))
+         (end (region-end))
+         (memed
+          (message
+           (s-trim-right
+            (apply #'string
+                   (-flatten
+                    (nreverse
+                     (-reduce-from (lambda (acc x)
+                                     (cons (cons x (-repeat (+ 1 (length acc)) 32)) acc))
+                                   '()
+                                   (string-to-list (buffer-substring-no-properties start end))))))))))
+
+    (save-excursion (delete-region start end)
+                    (goto-char start)
+                    (insert memed))))
 
 (provide 'functions)