From 3f376a431b927803e51b11b9ec5be6866910a0d9 Mon Sep 17 00:00:00 2001 From: ralesi Date: Fri, 30 Oct 2015 09:20:02 -0700 Subject: [PATCH] Prompt to open file literally when opening large files. --- core/core-dotspacemacs.el | 4 ++++ core/templates/.spacemacs.template | 3 +++ layers/+distribution/spacemacs-base/config.el | 3 +++ layers/+distribution/spacemacs-base/funcs.el | 9 +++++++++ 4 files changed, 19 insertions(+) diff --git a/core/core-dotspacemacs.el b/core/core-dotspacemacs.el index 39df87130..bbb3df1e5 100644 --- a/core/core-dotspacemacs.el +++ b/core/core-dotspacemacs.el @@ -176,6 +176,10 @@ start.") (defvar dotspacemacs-helm-position 'bottom "Position in which to show the `helm' mini-buffer.") +(defvar dotspacemacs-large-file-size 1 + "Size (in MB) above which spacemacs will prompt to open literally to avoid + performance issues.") + (defvar dotspacemacs-auto-save-file-location 'cache "Location where to auto-save files. Possible values are `original' to auto-save the file in-place, `cache' to auto-save the file to another diff --git a/core/templates/.spacemacs.template b/core/templates/.spacemacs.template index c42cbe5fb..1b0658ace 100644 --- a/core/templates/.spacemacs.template +++ b/core/templates/.spacemacs.template @@ -149,6 +149,9 @@ values." ;; If non nil then the last auto saved layouts are resume automatically upon ;; start. (default nil) dotspacemacs-auto-resume-layouts nil + ;; Buffer file size (in MB), above which spacemacs will prompt to open the + ;; buffer literally to improve performance. (default 1) + dotspacemacs-large-file-size 1 ;; Location where to auto-save files. Possible values are `original' to ;; auto-save the file in-place, `cache' to auto-save the file to another ;; file stored in the cache directory and `nil' to disable auto-saving. diff --git a/layers/+distribution/spacemacs-base/config.el b/layers/+distribution/spacemacs-base/config.el index 8beb1f273..681490934 100644 --- a/layers/+distribution/spacemacs-base/config.el +++ b/layers/+distribution/spacemacs-base/config.el @@ -161,6 +161,9 @@ It runs `tabulated-list-revert-hook', then calls `tabulated-list-print'." (with-eval-after-load 'comint (define-key comint-mode-map (kbd "C-d") nil)) +;; Prompt to open file literally if large file. +(add-hook 'find-file-hook 'spacemacs/check-large-file) + ;; whitespace-cleanup configuration (pcase dotspacemacs-whitespace-cleanup (`all (add-hook 'before-save-hook 'whitespace-cleanup)) diff --git a/layers/+distribution/spacemacs-base/funcs.el b/layers/+distribution/spacemacs-base/funcs.el index 1d6188ed0..9afee3dec 100644 --- a/layers/+distribution/spacemacs-base/funcs.el +++ b/layers/+distribution/spacemacs-base/funcs.el @@ -327,6 +327,15 @@ argument takes the kindows rotate backwards." (buffer-string))) (t (concat "/sudo:root@localhost:" fname)))))) +;; check when opening large files - literal file open +(defun spacemacs/check-large-file () + (when (> (nth 7 (file-attributes (buffer-file-name))) + (* 1024 1024 dotspacemacs-large-file-size)) + (when (y-or-n-p "This is a large file, open literally to avoid performance issues?") + (setq buffer-read-only t) + (buffer-disable-undo) + (fundamental-mode)))) + ;; found at http://emacswiki.org/emacs/KillingBuffers (defun spacemacs/kill-other-buffers () "Kill all other buffers."