From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Kevin Layer Newsgroups: gmane.emacs.devel Subject: Re: comint shell buffers autosaved to a file? Date: Wed, 28 Mar 2018 11:05:01 -0700 Message-ID: References: <87k1tx9ko8.fsf@linux-m68k.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="f403045c1b0a8b336805687cd8c4" X-Trace: blaine.gmane.org 1522260230 4806 195.159.176.226 (28 Mar 2018 18:03:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 28 Mar 2018 18:03:50 +0000 (UTC) Cc: Emacs-devel@gnu.org To: Andreas Schwab Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Mar 28 20:03:46 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f1FQH-00017G-Rs for ged-emacs-devel@m.gmane.org; Wed, 28 Mar 2018 20:03:46 +0200 Original-Received: from localhost ([::1]:40402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1FSJ-0004HP-NE for ged-emacs-devel@m.gmane.org; Wed, 28 Mar 2018 14:05:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1FRd-0004FD-I2 for Emacs-devel@gnu.org; Wed, 28 Mar 2018 14:05:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1FRX-0000CR-HB for Emacs-devel@gnu.org; Wed, 28 Mar 2018 14:05:09 -0400 Original-Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:52027) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1FRX-0000BD-6Y for Emacs-devel@gnu.org; Wed, 28 Mar 2018 14:05:03 -0400 Original-Received: by mail-wm0-x22e.google.com with SMTP id v21so6558732wmc.1 for ; Wed, 28 Mar 2018 11:05:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=known.net; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=iCEIW72FAzHdLiMyvIO1ta3E+KDDWr+UwxDpWZC04IQ=; b=k1nU6El3bOknaLYOef5VB0C5r5Mmd62xibZQsfFrU+RoXnFe9NQzIK/P6l0q8Rh/hA V/bDCLew0oLKAPzzVc+zJo4U3im80sq+6bto+r8L+b4nqu1QKUK6BKCbKtEgjn2ullX0 KXL9P03gUflmdxpa5VPWw2pWFxXhaxT4JEnik= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=iCEIW72FAzHdLiMyvIO1ta3E+KDDWr+UwxDpWZC04IQ=; b=LgSAHbVGDhm4+i0I2Z5PwLb+WmOVthXHn/ofRLa70GHWjSG3E1xaaDXMX/msWP9fal C0NgrcmiDDGUAQNjtH5GnjUohnXlJfJDVLwq8xCtqtwH6q7Hw+5HL3Z/L6sVVLV5u4Yu UjY8jx3Qtle+686hOryJCZjSiovHP/xHmJzHBqQ17HpEXQ2OCHyt4i9ycmKyI9rYNK4L 83V9jSrAXvc5KX74NYu9hE8kI/f6Wj6Wyq9IPXXdyPr0+DnvqcnyoHwQu/wXMd+e7lKj j89t6BgL11stjtKjzersQYMFH0pAqyblnjSOxumU7BnvF91TcI2II0pCJRf7aGHrCYEf L0UA== X-Gm-Message-State: AElRT7E7RFARLcfrOLOtuyrBWUW1ZHNND4J0sZ+iOigxX+oWT2yakTyR uVJRngpxuO5bHEZXHXI1reQ6rjnUuMa/xF5MLItkyQ== X-Google-Smtp-Source: AIpwx48QukhyANb6VGAPDLTQkkQUzxvjN6D6FF8rNb89oWKyh4wi37jftZwMLS0E/XvrzwRCfChG+mWtRBg+z4TjFtE= X-Received: by 10.80.153.68 with SMTP id l4mr4299826edb.179.1522260301779; Wed, 28 Mar 2018 11:05:01 -0700 (PDT) Original-Received: by 10.80.173.137 with HTTP; Wed, 28 Mar 2018 11:05:01 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:224124 Archived-At: --f403045c1b0a8b336805687cd8c4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I don't know if it's cool to share this here, but I wanted to in case someone else wanted to do the same, and have them save all in the same place: (defvar my-shell-auto-save-directory (expand-file-name "~/tmp/shell-auto-saves/")) ;; Make sure it exists, this is an important directory: (make-directory my-shell-auto-save-directory t) (defvar my-shell-auto-save-file-name-prefix (let ((s (system-name))) (when (string-match "\\(.*\\)\\.franz\\.com$" s) (setq s (substring s (match-beginning 1) (match-end 1)))) (format "%s-" s))) (defun my-make-shell-auto-save-file-name () (interactive) ;; debugging only (let* ((name (buffer-name)) base suffix) (when (string-match "^\\*\\(.*\\)\\*\\(<\\(.*\\)>\\)?$" name) (setq base (match-string 1 name)) (setq suffix (match-string 3 name)) (if suffix (format "%s%s%s-%s.log" my-shell-auto-save-directory my-shell-auto-save-file-name-prefix base suffix) (format "%s%s%s.log" my-shell-auto-save-directory my-shell-auto-save-file-name-prefix base))))) (defun my--around-advice--make-auto-save-file-name (orig-func) (let (fn) (cond ((and (null buffer-file-name) (or (eq 'ssh-mode major-mode) (eq 'shell-mode major-mode)) (setq fn (my-make-shell-auto-save-file-name))) fn) (t (funcall orig-func))))) (advice-add 'make-auto-save-file-name :around #'my--around-advice--make-auto-save-file-name) ;; Now, make sure auto-save-mode is on, for shell and ssh buffers: (defun my-turn-on-auto-save-mode-hook () (auto-save-mode 1)) (add-hook 'shell-mode-hook 'my-turn-on-auto-save-mode-hook t) (add-hook 'ssh-mode-hook 'my-turn-on-auto-save-mode-hook t) On Tue, Mar 27, 2018 at 4:42 PM, Kevin Layer wrote: > OK, the file was created after the auto-save-interval. Thanks, I'll thin= k > about whether this is good enough. > > On Tue, Mar 27, 2018 at 4:13 PM, Andreas Schwab > wrote: > >> On M=C3=A4r 27 2018, Kevin Layer wrote: >> >> > Any ideas on this? I'm willing to do some work to add it, if it's not >> too >> > hard. >> >> Just enable auto-save-mode. >> >> Andreas. >> >> -- >> Andreas Schwab, schwab@linux-m68k.org >> GPG Key fingerprint =3D 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4E= D5 >> "And now for something completely different." >> > > --f403045c1b0a8b336805687cd8c4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I don't know if it's cool to share this here, but = I wanted to in case someone else wanted to do the same, and have them save = all in the same place:

(defvar my-shell-auto-save-d= irectory
=C2=A0 =C2=A0 (expand-file-name "~/tmp/shell-auto-s= aves/"))

;; Make sure it exists, this is an i= mportant directory:
(make-directory my-shell-auto-save-directory = t)

(defvar my-shell-auto-save-file-name-prefix
=C2=A0 =C2=A0 (let ((s (system-name)))
=C2=A0 =C2=A0 =C2= =A0 (when (string-match "\\(.*\\)\\.franz\\.com$" s)
(setq s (substring s (match-beginning= 1) (match-end 1))))
=C2=A0 =C2=A0 =C2=A0 (format "%s-"= s)))

(defun my-make-shell-auto-save-file-name ()<= /div>
=C2=A0 (interactive) ;; debugging only
=C2=A0 (let* ((n= ame (buffer-name))
base = suffix)
=C2=A0 =C2=A0 (when (string-match "^\\*\\(.*\\)\\*\\= (<\\(.*\\)>\\)?$" name)
=C2=A0 =C2=A0 =C2=A0 (setq bas= e (match-string 1 name))
=C2=A0 =C2=A0 =C2=A0 (setq suffix (match= -string 3 name))
=C2=A0 =C2=A0 =C2=A0 (if suffix
=C2=A0 (format "%s%s%s-%s.log" = my-shell-auto-save-directory
=C2=A0 =C2=A0my-shell-auto-save-file-name-prefix
=C2=A0 =C2=A0base suffix)
(format "%s%s%s.log" my-shell-auto= -save-directory
my-shel= l-auto-save-file-name-prefix base)))))

(defun my--= around-advice--make-auto-save-file-name (orig-func)
=C2=A0 (let (= fn)
=C2=A0 =C2=A0 (cond
=C2=A0 =C2=A0 =C2=A0((and (null= buffer-file-name)
=C2=A0= =C2=A0(or (eq 'ssh-mode major-mode) (eq 'shell-mode major-mode))
=C2=A0 =C2=A0(setq fn (my-= make-shell-auto-save-file-name)))
=C2=A0 =C2=A0 =C2=A0 fn)
<= div>=C2=A0 =C2=A0 =C2=A0(t (funcall orig-func)))))

(advice-add 'make-auto-save-file-name
=C2=A0 =C2=A0 :around
=C2=A0 =C2=A0 #'my--around-advice--make-auto-save-file-n= ame)

;; Now, make sure auto-save-mode is on, for s= hell and ssh buffers:

(defun my-turn-on-auto-save-= mode-hook ()
=C2=A0 (auto-save-mode 1))

= (add-hook 'shell-mode-hook 'my-turn-on-auto-save-mode-hook t)
=
(add-hook 'ssh-mode-hook 'my-turn-on-auto-save-mode-hook t)


On Tue, Mar 27, 2018 at 4:42 PM, Kevin Layer <layer@known.net> wrote:
OK,= the file was created after the auto-save-interval.=C2=A0 Thanks, I'll = think about whether this is good enough.
On Tue, Mar 27, 2018 at 4:13 = PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
On M=C3=A4r= 27 2018, Kevin Layer <layer@known.net> wrote:

> Any ideas on this?=C2=A0 I'm willing to do some work to add it, if= it's not too
> hard.

Just enable auto-save-mode.

Andreas.

--
Andreas Schwab, = schwab@linux-m68k.org
GPG Key fingerprint =3D 58CA 54C7 6D53 942B 1756=C2=A0 01D3 44D5 214B 8276 = 4ED5
"And now for something completely different."


--f403045c1b0a8b336805687cd8c4--