[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Friendlier dired experience [CODE INCLUDED]
From: |
Boruch Baum |
Subject: |
Re: Friendlier dired experience [CODE INCLUDED] |
Date: |
Thu, 5 Nov 2020 03:54:40 -0500 |
User-agent: |
NeoMutt/20180716 |
On 2020-11-04 20:57, Michael Albinus wrote:
> When I'm working in a remote buffer, "diredc-trash-info" does not
> work. This is because you call shell-command, which runs the command on
> the remote host.
>
> When I have trashed a file, say "/ssh:ford:/tmp/xxx", it appears as
> "/home/albinus/.local/share/Trash/files/xxx", in the local trash can.
> "/home/albinus/.local/share/Trash/info/xxx.trashinfo" contains the line
>
> Path=/ssh%3aford%3a/tmp/xxx
>
> as expected. However, "M-x diredc-trash-restore" returns with the error
>
> dired-rename-file: Renaming: No such file or directory,
> /home/albinus/.local/share/Trash/files/xxx, /ssh%3aford%3a/tmp/xxx
>
> I believe you must unhexlify the path in the .trashinfo. This is not
> only because of Tramp. A local file "/tmp/file with space", trashed via
> "M-x move-file-to-trash", has the entry
>
> Path=/tmp/file%20with%20space
>
> Calling "M-x diredc-trash-restore" restores it to "/tmp/file%20with%20space".
I was surprised that this turned out so difficult for me to do. The very
simple case for 8-bit ascii was easily handled by unhexlifying, but that
simple case got me thinking about unicode file names. Sure enough, the
trash meta-data for such file names are also hex encoded, but the
standard elisp commands I could find wouldn't handle them. Have I
overlooked something? The following code snippet performs two alternate
techniques (url-unhex-string, stolen-from-emacs-w3m-url-decode-string)
first for a simple case of a file name with an embedded space, and then
on a unicode file name. Only the function shamelessly stolen from the
emacs-w3m package worked for both cases. Tell me I've overlooked
something, please.
(cl-flet
((stolen-from-emacs-w3m-url-decode-string (str &optional coding regexp)
(or regexp (setq regexp "%\\(?:\\([0-9a-f][0-9a-f]\\)\\|0d%0a\\)"))
(let ((start 0)
(case-fold-search t))
(with-temp-buffer
(set-buffer-multibyte nil)
(while (string-match regexp str start)
(insert (substring str start (match-beginning 0))
(if (match-beginning 1)
(string-to-number (match-string 1 str) 16)
?\n))
(setq start (match-end 0)))
(insert (substring str start))
(decode-coding-string
(buffer-string)
(or (if (listp coding)
(with-coding-priority coding
(car (detect-coding-region (point-min) (point-max))))
coding)
'iso-8859-1))))))
(dolist (str '("hello%20world"
"%d7%a9%d7%9c%d7%95%d7%9d%20%d7%a2%d7%95%d7%9c%d7%9d"))
(insert (format "\n\nurl-unhex: %s\nw3m-url-decode: %s"
(url-unhex-string str)
(stolen-from-emacs-w3m-url-decode-string str)))))
--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0
- Re: Friendlier dired experience [CODE INCLUDED], (continued)
- Re: Friendlier dired experience [CODE INCLUDED], Stefan Kangas, 2020/11/03
- Re: Friendlier dired experience [CODE INCLUDED], Jean Louis, 2020/11/03
- Re: Friendlier dired experience [CODE INCLUDED], Boruch Baum, 2020/11/03
- Re: Friendlier dired experience [CODE INCLUDED], Michael Albinus, 2020/11/03
- Re: Friendlier dired experience [CODE INCLUDED], Boruch Baum, 2020/11/03
- Re: Friendlier dired experience [CODE INCLUDED], Jean Louis, 2020/11/03
- Re: Friendlier dired experience [CODE INCLUDED], Pankaj Jangid, 2020/11/04
- Re: Friendlier dired experience [CODE INCLUDED], Michael Albinus, 2020/11/04
- Re: Friendlier dired experience [CODE INCLUDED], Yuri Khan, 2020/11/04
- Re: Friendlier dired experience [CODE INCLUDED], Michael Albinus, 2020/11/04
- Re: Friendlier dired experience [CODE INCLUDED],
Boruch Baum <=
- Re: Friendlier dired experience [CODE INCLUDED], Eli Zaretskii, 2020/11/05
- Re: Friendlier dired experience [CODE INCLUDED], Jean Louis, 2020/11/05
- Re: Friendlier dired experience [CODE INCLUDED], Stefan Kangas, 2020/11/04
- Re: Friendlier dired experience [CODE INCLUDED], Boruch Baum, 2020/11/04
- Re: Friendlier dired experience [CODE INCLUDED], Stefan Kangas, 2020/11/05
- Re: Friendlier dired experience [CODE INCLUDED], Boruch Baum, 2020/11/06
Re: Friendlier dired experience [CODE INCLUDED], Stefan Monnier, 2020/11/04