unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#31317: 26.1; Add a tramp-make-tramp-temp-file* variant which returns the full tramp filename?
@ 2018-04-30 12:56 Phil Sainty
  2018-04-30 13:20 ` Michael Albinus
  0 siblings, 1 reply; 5+ messages in thread
From: Phil Sainty @ 2018-04-30 12:56 UTC (permalink / raw)
  To: 31317

I have a tramp use-case where I want to create a temporary file
on the remote host and then populate that file via elisp -- I am
using (with-temp-file tramp-file-name (insert contents)) -- and
`tramp-make-tramp-temp-file' doesn't seem to facilitate this
nicely due to it returning only the local part of the generated
filename, which means I need to *recreate* the full tramp path
for that file before I can edit the file.

At present I am using `tramp-make-tramp-file-name' using the
returned local path and the original vector passed to
`tramp-make-tramp-temp-file'; but as well as being cumbersome,
I don't like making the assumption that I'm always going to get
the correct value (even if it turns out that I would in practice).

(I should perhaps even be dissecting the return value of
`tramp-get-remote-tmpdir' to obtain a new vector to recreate
that full path with, but that's even more work, and it looks
like it would wind up being the same values...)

It would seem useful to split `tramp-make-tramp-temp-file' into
two functions; one to generate the temporary file and return the
full path, and the other to return the localname.

Does the following seem reasonable?


(defun tramp-make-tramp-temp-file (vec)
   "Create a temporary file on the remote host identified by VEC.
Return the local name of the temporary file."
   (with-parsed-tramp-file-name (tramp-make-tramp-temp-file* vec)
       nil localname))

(defun tramp-make-tramp-temp-file* (vec)
   "Create a temporary file on the remote host identified by VEC.
Return the full tramp file name of the temporary file."
   (let ((prefix (expand-file-name
                  tramp-temp-name-prefix (tramp-get-remote-tmpdir vec)))
         result)
     (while (not result)
       ;; `make-temp-file' would be the natural choice for
       ;; implementation.  But it calls `write-region' internally,
       ;; which also needs a temporary file - we would end in an
       ;; infinite loop.
       (setq result (make-temp-name prefix))
       (if (file-exists-p result)
           (setq result nil)
         ;; This creates the file by side effect.
         (set-file-times result)
         (set-file-modes result (string-to-number "0700" 8))))
     result))



In GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll 
bars)
  of 2018-04-15 built on shodan
Windowing system distributor 'The X.Org Foundation', version 
11.0.11804000
System Description:	Ubuntu 16.04.4 LTS

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll 
bars) of 2018-04-15
uncompressing tramp.el.gz...done
Making completion list...

Configured using:
  'configure --prefix=/home/phil/emacs/26.1rc1/usr/local
  --with-x-toolkit=lucid --without-sound'

Configured features:
XAW3D XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK DBUS GSETTINGS NOTIFY
GNUTLS LIBXML2 FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11 THREADS
LCMS2

Important settings:
   value of $LANG: en_NZ.UTF-8
   locale-coding-system: utf-8

Major mode: Emacs-Lisp

Minor modes in effect:
   show-paren-mode: t
   minibuffer-depth-indicate-mode: t
   winner-mode: t
   global-hl-line-mode: t
   tooltip-mode: t
   global-eldoc-mode: t
   eldoc-mode: t
   electric-indent-mode: t
   mouse-wheel-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t
   line-number-mode: t
   transient-mark-mode: (only . t)

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny seq byte-opt gv
bytecomp byte-compile cconv cl-loaddefs cl-lib format-spec rfc822 mml
mml-sec password-cache epa derived epg epg-config gnus-util rmail
rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils imenu jka-compr thingatpt find-func
dired-x easymenu paren mb-depth winner ring hl-line dired dired-loaddefs
advice elec-pair time-date mule-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow isearch timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript charprop case-table epa-hook jka-cmpr-hook
help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 104217 8935)
  (symbols 48 20906 1)
  (miscs 40 407 318)
  (strings 32 31341 1364)
  (string-bytes 1 821008)
  (vectors 16 14887)
  (vector-slots 8 500084 10656)
  (floats 8 60 400)
  (intervals 56 546 22)
  (buffers 992 15)
  (heap 1024 41834 1175))






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#31317: 26.1; Add a tramp-make-tramp-temp-file* variant which returns the full tramp filename?
  2018-04-30 12:56 bug#31317: 26.1; Add a tramp-make-tramp-temp-file* variant which returns the full tramp filename? Phil Sainty
@ 2018-04-30 13:20 ` Michael Albinus
  2018-04-30 13:55   ` Phil Sainty
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Albinus @ 2018-04-30 13:20 UTC (permalink / raw)
  To: Phil Sainty; +Cc: 31317

Phil Sainty <psainty@orcon.net.nz> writes:

Hi Phil,

> I have a tramp use-case where I want to create a temporary file
> on the remote host and then populate that file via elisp -- I am
> using (with-temp-file tramp-file-name (insert contents)) -- and
> `tramp-make-tramp-temp-file' doesn't seem to facilitate this
> nicely due to it returning only the local part of the generated
> filename, which means I need to *recreate* the full tramp path
> for that file before I can edit the file.

What about `make-nearby-temp-file'?

Best regards, Michael.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#31317: 26.1; Add a tramp-make-tramp-temp-file* variant which returns the full tramp filename?
  2018-04-30 13:20 ` Michael Albinus
@ 2018-04-30 13:55   ` Phil Sainty
  2018-04-30 14:10     ` Michael Albinus
  0 siblings, 1 reply; 5+ messages in thread
From: Phil Sainty @ 2018-04-30 13:55 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 31317, bug-gnu-emacs

On 2018-05-01 01:20, Michael Albinus wrote:
> What about `make-nearby-temp-file'?

Thanks Michael.  I see that this is new to 26.1.

> ** The new functions 'make-nearby-temp-file' and 
> 'temporary-file-directory'
> can be used for creation of temporary files on remote or mounted 
> directories.

That certainly does the trick.

Would it make sense for `tramp-make-tramp-temp-file' to be utilising 
that
function?  (i.e. composing a tramp file name from VEC and then handing 
off
to `make-nearby-temp-file' ?)


-Phil






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#31317: 26.1; Add a tramp-make-tramp-temp-file* variant which returns the full tramp filename?
  2018-04-30 13:55   ` Phil Sainty
@ 2018-04-30 14:10     ` Michael Albinus
  2018-04-30 14:37       ` Phil Sainty
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Albinus @ 2018-04-30 14:10 UTC (permalink / raw)
  To: Phil Sainty; +Cc: 31317, bug-gnu-emacs

Phil Sainty <psainty@orcon.net.nz> writes:

Hi Phil,

> That certainly does the trick.

Yep, I'm closing this bug.

> Would it make sense for `tramp-make-tramp-temp-file' to be utilising
> that function?  (i.e. composing a tramp file name from VEC and then
> handing off to `make-nearby-temp-file' ?)

No, see the comment inside `tramp-make-tramp-temp-file'.  It must use
`make-temp-name' instead of `make-temp-file'.

> -Phil

Best regards, Michael.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#31317: 26.1; Add a tramp-make-tramp-temp-file* variant which returns the full tramp filename?
  2018-04-30 14:10     ` Michael Albinus
@ 2018-04-30 14:37       ` Phil Sainty
  0 siblings, 0 replies; 5+ messages in thread
From: Phil Sainty @ 2018-04-30 14:37 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 31317, bug-gnu-emacs

On 2018-05-01 02:10, Michael Albinus wrote:
> Phil Sainty <psainty@orcon.net.nz> writes:
>> Would it make sense for `tramp-make-tramp-temp-file' to be utilising
>> that function?  (i.e. composing a tramp file name from VEC and then
>> handing off to `make-nearby-temp-file' ?)
> 
> No, see the comment inside `tramp-make-tramp-temp-file'.  It must use
> `make-temp-name' instead of `make-temp-file'.

I'm rather confused about why there would be a danger of an infinite
loop if `tramp-make-tramp-temp-file' called `make-nearby-temp-file',
if that (presumably) is not a danger if I call `make-nearby-temp-file'
in a tramp context?

I'm obviously missing something.  Never mind.  Thank you for pointing
me to the new function!


-Phil






^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-04-30 14:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-30 12:56 bug#31317: 26.1; Add a tramp-make-tramp-temp-file* variant which returns the full tramp filename? Phil Sainty
2018-04-30 13:20 ` Michael Albinus
2018-04-30 13:55   ` Phil Sainty
2018-04-30 14:10     ` Michael Albinus
2018-04-30 14:37       ` Phil Sainty

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).