- ;; I need this function here, where INSIDE_EMACS is replaced with RLC_INSIDE_EMACS.
- ;; ian: last update 2017-1-7. update this periodically from upstream
- ;; like when we do a major emacs update
- (defun comint-exec-1 (name buffer command switches)
- (let ((process-environment
- (nconc
- ;; If using termcap, we specify `emacs' as the terminal type
- ;; because that lets us specify a width.
- ;; If using terminfo, we specify `dumb' because that is
- ;; a defined terminal type. `emacs' is not a defined terminal type
- ;; and there is no way for us to define it here.
- ;; Some programs that use terminfo get very confused
- ;; if TERM is not a valid terminal type.
- ;; ;; There is similar code in compile.el.
- (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
- (list "TERM=dumb" "TERMCAP="
- (format "COLUMNS=%d" (window-width)))
- (list "TERM=emacs"
- (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width))))
- (list (format "RLC_INSIDE_EMACS=%s,comint" emacs-version))
- process-environment))
- (default-directory
- (if (file-accessible-directory-p default-directory)
- default-directory
- "/"))
- proc decoding encoding changed)
- (let ((exec-path (if (and command (file-name-directory command))
- ;; If the command has slashes, make sure we
- ;; first look relative to the current directory.
- (cons default-directory exec-path) exec-path)))
- (setq proc (apply 'start-file-process name buffer command switches)))
- ;; Some file name handler cannot start a process, fe ange-ftp.
- (unless (processp proc) (error "No process started"))
- (let ((coding-systems (process-coding-system proc)))
- (setq decoding (car coding-systems)
- encoding (cdr coding-systems)))
- ;; Even if start-file-process left the coding system for encoding data
- ;; sent from the process undecided, we had better use the same one
- ;; as what we use for decoding. But, we should suppress EOL
- ;; conversion.
- (if (and decoding (not encoding))
- (setq encoding (coding-system-change-eol-conversion decoding 'unix)
- changed t))
- (if changed
- (set-process-coding-system proc decoding encoding))
- proc))
-
-;;; auto save & backup
- (setq auto-save-timeout 1) ; idle time before auto-save.
-
- ;; main hook for my auto save
- (add-hook 'auto-save-hook 'my-auto-save)
- ;; additional hook to try to deal with emacs not auto-saving when a buffer isn't active
- (add-hook 'window-configuration-change-hook 'my-auto-save-win)
-
- ;; this function from mu4e really does not like buffer saving
- (advice-add 'message-send-and-exit :before 'my-as-off)
- (advice-add 'message-send-and-exit :after 'my-as-on)
-
- ;; avoid window config hook saving too much, it can
- ;; get into loops in some random situations
- (setq my-auto-save-last nil)
- (defun my-auto-save-win ()
- (unless (eq (current-buffer) my-auto-save-last)
- (my-auto-save (current-buffer))))
-
- (defun my-auto-save (&optional last)
- (when (and
- my-as
- (buffer-file-name)
- ;; mu4e has a bug right now, undo breaks when saving drafts
- (not (string= (buffer-file-name) "*draft*"))
- (buffer-modified-p)
- (not (and (boundp 'org-src-edit-buffer-p) (org-src-edit-buffer-p))))
- ;; serial is incremented on each save, so let's do a bit less of them
- (not (derived-mode-p 'dns-mode))
- (setq my-auto-save-last last)
- (let (message-log-max)
- ;; a bit of a hack to partially suppress the constant saving in the echo area
- (with-temp-message ""
- (basic-save-buffer)))))
-
- ;; in the message-send-and-exit advice, got an error because it passed an arg.
- ;; didn't look into why, just add ignored args.
- (defun my-as-off (&rest ignore)
- (interactive)
- (setq my-as nil))
-
- (defun my-as-off-local (&rest ignore)
- (interactive)
- (setq-local my-as nil))
-
- (defun my-as-on (&rest ignore)
- (interactive)
- (setq my-as t))
-
- (defun my-as-on-local (&rest ignore)
- (interactive)
- (setq-local my-as on))
-
- ;; based on suggestion in the emacs docs, redefine these 2 functions
- ;; to avoid prompt spamming the user when we do auto-save
- (defun ask-user-about-supersession-threat (fn)
- (discard-input)
- (message
- "File for %s has changed on disk outside of emacs. Auto-save is overwriting it, however
+;; I need this function here, where INSIDE_EMACS is replaced with LC_INSIDE_EMACS.
+;; ian: last update 2017-1-7. update this periodically from upstream
+;; like when we do a major emacs update
+(defun comint-exec-1 (name buffer command switches)
+ (let ((process-environment
+ (nconc
+ ;; If using termcap, we specify `emacs' as the terminal type
+ ;; because that lets us specify a width.
+ ;; If using terminfo, we specify `dumb' because that is
+ ;; a defined terminal type. `emacs' is not a defined terminal type
+ ;; and there is no way for us to define it here.
+ ;; Some programs that use terminfo get very confused
+ ;; if TERM is not a valid terminal type.
+ ;; ;; There is similar code in compile.el.
+ (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
+ (list "TERM=dumb" "TERMCAP="
+ (format "COLUMNS=%d" (window-width)))
+ (list "TERM=emacs"
+ (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width))))
+ (list (format "LC_INSIDE_EMACS=%s,comint" emacs-version))
+ process-environment))
+ (default-directory
+ (if (file-accessible-directory-p default-directory)
+ default-directory
+ "/"))
+ proc decoding encoding changed)
+ (let ((exec-path (if (and command (file-name-directory command))
+ ;; If the command has slashes, make sure we
+ ;; first look relative to the current directory.
+ (cons default-directory exec-path) exec-path)))
+ (setq proc (apply 'start-file-process name buffer command switches)))
+ ;; Some file name handler cannot start a process, fe ange-ftp.
+ (unless (processp proc) (error "No process started"))
+ (let ((coding-systems (process-coding-system proc)))
+ (setq decoding (car coding-systems)
+ encoding (cdr coding-systems)))
+ ;; Even if start-file-process left the coding system for encoding data
+ ;; sent from the process undecided, we had better use the same one
+ ;; as what we use for decoding. But, we should suppress EOL
+ ;; conversion.
+ (if (and decoding (not encoding))
+ (setq encoding (coding-system-change-eol-conversion decoding 'unix)
+ changed t))
+ (if changed
+ (set-process-coding-system proc decoding encoding))
+ proc))
+
+;;; auto save
+
+;; todo: patch this so i can turn it off like my-as-off-local.
+;; then try it out and see if it can replace my autosave.
+;; Or maybe with the new auto-save-visited-mode.
+;; (use-package super-save
+;; :ensure t
+;; :config
+;; (setq super-save-exclude '("")
+;; super-save-triggers
+;; '(balance-windows
+;; next-buffer
+;; org-babel-execute-src-block
+;; other-window
+;; previous-buffer
+;; split-window-below
+;; split-window-horizontally
+;; start-process-shell-command
+;; switch-to-buffer
+;; windmove-down
+;; windmove-left
+;; windmove-right
+;; windmove-up)
+;; )
+;; (super-save-mode +1))
+
+
+
+(setq auto-save-timeout 1) ; idle time before auto-save.
+
+;; main hook for my auto save
+(add-hook 'auto-save-hook 'my-auto-save)
+;; additional hook to try to deal with emacs not auto-saving when a buffer isn't active
+(add-hook 'window-configuration-change-hook 'my-auto-save-win)
+
+;; this function from mu4e really does not like buffer saving
+(advice-add 'message-send-and-exit :before 'my-as-off)
+(advice-add 'message-send-and-exit :after 'my-as-on)
+
+;; avoid window config hook saving too much, it can
+;; get into loops in some random situations
+(defvar my-auto-save-last nil)
+(defvar my-as nil)
+(defvar my-auto-save-last nil)
+(defun my-auto-save-win ()
+ (unless (eq (current-buffer) my-auto-save-last)
+ (my-auto-save (current-buffer))))
+
+(defun my-auto-save (&optional last)
+ (when (and
+ my-as
+ (buffer-file-name)
+ ;; mu4e has a bug right now, undo breaks when saving drafts
+ (not (string= (buffer-file-name) "*draft*"))
+ (buffer-modified-p)
+ (not (and (boundp 'org-src-edit-buffer-p) (org-src-edit-buffer-p))))
+ ;; serial is incremented on each save, so let's do a bit less of them
+ (not (derived-mode-p 'dns-mode))
+ (setq my-auto-save-last last)
+ (let (message-log-max)
+ ;; a bit of a hack to partially suppress the constant saving in the echo area
+ (with-temp-message ""
+ (basic-save-buffer)))))
+
+;; in the message-send-and-exit advice, got an error because it passed an arg.
+;; didn't look into why, just add ignored args.
+(defun my-as-off (&rest ignore)
+ (interactive)
+ (setq my-as nil))
+
+(defun my-as-off-local (&rest ignore)
+ (interactive)
+ (setq-local my-as nil))
+
+(defun my-as-on (&rest ignore)
+ (interactive)
+ (setq my-as t))
+
+(defun my-as-on-local (&rest ignore)
+ (interactive)
+ (setq-local my-as t))
+
+;; based on suggestion in the emacs docs, redefine these 2 functions
+;; to avoid prompt spamming the user when we do auto-save
+(defun ask-user-about-supersession-threat (fn)
+ (discard-input)
+ (message
+ "File for %s has changed on disk outside of emacs. Auto-save is overwriting it, however