all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Function to find symlink target
@ 2022-05-18 20:55 Jean Louis
  2022-05-18 23:00 ` Emanuel Berg
  2022-05-19 23:14 ` Nick Dokos
  0 siblings, 2 replies; 41+ messages in thread
From: Jean Louis @ 2022-05-18 20:55 UTC (permalink / raw)
  To: Help GNU Emacs

Hello,

I have made this function to find the target of a symlink in dired, it opens
new Dired window and tries to locate the file. I have tried finding
such function in Dired and did not succeed, maybe it exists in Emacs
programs somewhere.

(defun rcd-dired-find-symlink ()
  "Find target of a symlink"
  (interactive)
  (when (dired-get-marked-files)
    (let ((file (car (dired-get-marked-files))))
      (if (file-symlink-p file)
	  (let* ((file (file-truename file))
		 (directory (file-name-directory file))
		 (file (file-name-nondirectory file))
		 (back (length file)))
	    (find-file directory)
	    (search-forward file)
	    (backward-char back))
	(message "Not a symlink: %s" file)))))


Let me know if I should improve this by any means.

Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/




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

* Re: Function to find symlink target
  2022-05-18 20:55 Function to find symlink target Jean Louis
@ 2022-05-18 23:00 ` Emanuel Berg
  2022-05-22 13:52   ` Jean Louis
  2022-05-19 23:14 ` Nick Dokos
  1 sibling, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-05-18 23:00 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> (defun rcd-dired-find-symlink ()
>   "Find target of a symlink"
>   (interactive)
>   (when (dired-get-marked-files)
>     (let ((file (car (dired-get-marked-files))))
>       (if (file-symlink-p file)
> 	  (let* ((file (file-truename file))
> 		 (directory (file-name-directory file))
> 		 (file (file-name-nondirectory file))
> 		 (back (length file)))
> 	    (find-file directory)
> 	    (search-forward file)
> 	    (backward-char back))
> 	(message "Not a symlink: %s" file)))))
>
> Let me know if I should improve this by any means.

Hello again Jean!

1. Do auto-indentation ...

2. `require' is needed for `dired-get-marked-files', do
   byte-compile to find out and always do that before
   posting here.

3. The defun has a confusing name, you have already found the
   symlink one would think?
  
4. Emacs thinks of the docstring that the "[f]irst sentence
   should end with punctuation". Always do the style check
   before posting here BTW, here's an example how. [1]
 
5. `dired-get-marked-files' is invoked twice, instead just do
    it once and reuse the result with and in `let'.

6. "file" appears as a let-binding twice in `let*', confusing
   and probably no good reason to do so either, right?

7. I'm unsure but if you `find-file' a directory that is
   already open in a buffer, you still end up at `point-min'?
   If you don't, you need to got there before the search,
   (goto-char (point-min)) as you know.
   
8. Instead of doing `backward-char', do something like this:
   [you can try it below as well]

(when (search-forward "key" (point-max) t)
  (goto-char (match-beginning 0)) )

key

Wow, 8 paragraphs! That's what I call feedback ...

[1] https://dataswamp.org/~incal/emacs-init/ide/pack-style.el

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-18 20:55 Function to find symlink target Jean Louis
  2022-05-18 23:00 ` Emanuel Berg
@ 2022-05-19 23:14 ` Nick Dokos
  2022-05-20  0:42   ` Emanuel Berg
  2022-05-23  8:17   ` Jean Louis
  1 sibling, 2 replies; 41+ messages in thread
From: Nick Dokos @ 2022-05-19 23:14 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis <bugs@gnu.support> writes:

> Hello,
>
> I have made this function to find the target of a symlink in dired, it opens
> new Dired window and tries to locate the file. I have tried finding
> such function in Dired and did not succeed, maybe it exists in Emacs
> programs somewhere.
>

C-h f file-symlink-p

-- 
Nick

"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler




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

* Re: Function to find symlink target
  2022-05-19 23:14 ` Nick Dokos
@ 2022-05-20  0:42   ` Emanuel Berg
  2022-05-23  8:17   ` Jean Louis
  1 sibling, 0 replies; 41+ messages in thread
From: Emanuel Berg @ 2022-05-20  0:42 UTC (permalink / raw)
  To: help-gnu-emacs

Nick Dokos wrote:

>> I have made this function to find the target of a symlink
>> in dired [...]
>
> C-h f file-symlink-p

Lame provocation, it even says

  This function does not check whether the link target exists.

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-18 23:00 ` Emanuel Berg
@ 2022-05-22 13:52   ` Jean Louis
  2022-05-22 18:02     ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Jean Louis @ 2022-05-22 13:52 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <incal@dataswamp.org> [2022-05-19 02:02]:
> Jean Louis wrote:
> 
> > (defun rcd-dired-find-symlink ()
> >   "Find target of a symlink"
> >   (interactive)
> >   (when (dired-get-marked-files)
> >     (let ((file (car (dired-get-marked-files))))
> >       (if (file-symlink-p file)
> > 	  (let* ((file (file-truename file))
> > 		 (directory (file-name-directory file))
> > 		 (file (file-name-nondirectory file))
> > 		 (back (length file)))
> > 	    (find-file directory)
> > 	    (search-forward file)
> > 	    (backward-char back))
> > 	(message "Not a symlink: %s" file)))))
> >
> > Let me know if I should improve this by any means.
> 
> Hello again Jean!
> 
> 1. Do auto-indentation ...

Thanks. Thought it indended in my file. Maybe email copy and paste
changed something.

> 2. `require' is needed for `dired-get-marked-files', do
>    byte-compile to find out and always do that before
>    posting here.

If you mean (require 'dired) that is in my file. I understand.

> 3. The defun has a confusing name, you have already found the
>    symlink one would think?

I will call it: `rcd-dired-show-symlink-target'

> 4. Emacs thinks of the docstring that the "[f]irst sentence
>    should end with punctuation". Always do the style check
>    before posting here BTW, here's an example how. [1]

OK. Like this:

(defun rcd-dired-show-symlink-target ()
  "Show target of a symlink."

> 5. `dired-get-marked-files' is invoked twice, instead just do
>     it once and reuse the result with and in `let'.


> 
> 6. "file" appears as a let-binding twice in `let*', confusing
>    and probably no good reason to do so either, right?
> 
> 7. I'm unsure but if you `find-file' a directory that is
>    already open in a buffer, you still end up at `point-min'?
>    If you don't, you need to got there before the search,
>    (goto-char (point-min)) as you know.
>    
> 8. Instead of doing `backward-char', do something like this:
>    [you can try it below as well]
> 
> (when (search-forward "key" (point-max) t)
>   (goto-char (match-beginning 0)) )

(defun rcd-dired-show-symlink-target ()
  "Show target of a symlink."
  (interactive)
  (let ((file (car (dired-get-marked-files))))
    (if (and file (file-symlink-p file))
      (let* ((target (file-truename file))
	     (target-exists (file-exists-p target))
	     (directory (file-name-directory target))
	     (target (file-name-nondirectory target)))
	(if target-exists
	    (progn
	      (find-file directory)
	      (when (search-forward target (point-max) t)
		(goto-char (match-beginning 0))))
	  (message "Target does not exist: %s" target)))
      (message "Not a symlink: %s" file))))

Yes, I have tried this, and now I see that finding is not accurate.

Example is this one:

S lrwxrwxrwx     1    8 May 22 16:15 test1.pdf -> test.pdf
  -rw-r--r--     1   90 May 22 15:24 basic.yml
  -rw-r--r--     1  15K May 22 15:13 test.pdf

as if I invoke function on first line it will come to -> test.pdf
which is not what I would like.

Then I have tried with this version, unsuccessfully:

(defun rcd-dired-show-symlink-target ()
  "Show target of a symlink."
  (interactive)
  (let ((file (car (dired-get-marked-files))))
    (if (and file (file-symlink-p file))
      (let* ((target (file-truename file))
	     (target-exists (file-exists-p target))
	     (directory (file-name-directory target))
	     (search (concat "\d\d " (file-name-nondirectory target))))
	(if target-exists
	    (progn
	      (find-file directory)
	      (when (search-forward-regexp search (point-max) t)
		(goto-char (match-beginning 0))))
	  (message "Target does not exist: %s" target)))
      (message "Not a symlink: %s" file))))

as for that version I think that at least 2 digits should be included
before the space when searching in Dired and I am doing something
wrong.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Function to find symlink target
  2022-05-22 13:52   ` Jean Louis
@ 2022-05-22 18:02     ` Emanuel Berg
  2022-05-23  9:05       ` Jean Louis
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-05-22 18:02 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> Example is this one:
>
> S lrwxrwxrwx     1    8 May 22 16:15 test1.pdf -> test.pdf
>   -rw-r--r--     1   90 May 22 15:24 basic.yml
>   -rw-r--r--     1  15K May 22 15:13 test.pdf
>
> as if I invoke function on first line it will come to ->
> test.pdf which is not what I would like.

Right, I see. Okey then, put the search in a loop and upon
every hit goto the beginning of the match and do

  (get-text-property (point) 'dired-filename)

this will be true for the third line's test.pdf but not
the first.

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-19 23:14 ` Nick Dokos
  2022-05-20  0:42   ` Emanuel Berg
@ 2022-05-23  8:17   ` Jean Louis
  2022-05-23 22:49     ` Michael Heerdegen
  1 sibling, 1 reply; 41+ messages in thread
From: Jean Louis @ 2022-05-23  8:17 UTC (permalink / raw)
  To: Nick Dokos; +Cc: help-gnu-emacs

* Nick Dokos <ndokos@gmail.com> [2022-05-20 02:16]:
> Jean Louis <bugs@gnu.support> writes:
> 
> > Hello,
> >
> > I have made this function to find the target of a symlink in dired, it opens
> > new Dired window and tries to locate the file. I have tried finding
> > such function in Dired and did not succeed, maybe it exists in Emacs
> > programs somewhere.
> >
> 
> C-h f file-symlink-p

Thanks. I use that in the function mentioned.

In my Rox Filer I have the option to "Show Target" of a symbolic link,
that one is useful function, and I assumed that it must exist in Emacs
but did not find it.

It is like jumping to other file in Dired.

Is there maybe some Dired function to jump exactly to specific file name?


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Function to find symlink target
  2022-05-22 18:02     ` Emanuel Berg
@ 2022-05-23  9:05       ` Jean Louis
  2022-05-23 20:46         ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Jean Louis @ 2022-05-23  9:05 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <incal@dataswamp.org> [2022-05-22 21:04]:
> Jean Louis wrote:
> 
> > Example is this one:
> >
> > S lrwxrwxrwx     1    8 May 22 16:15 test1.pdf -> test.pdf
> >   -rw-r--r--     1   90 May 22 15:24 basic.yml
> >   -rw-r--r--     1  15K May 22 15:13 test.pdf
> >
> > as if I invoke function on first line it will come to ->
> > test.pdf which is not what I would like.
> 
> Right, I see. Okey then, put the search in a loop and upon
> every hit goto the beginning of the match and do
> 
>   (get-text-property (point) 'dired-filename)
> 
> this will be true for the third line's test.pdf but not
> the first.

When I evaluate it, I get t only, I do not understand. Tell me more
about the idea of finding particular file in dired list and placing
cursor on it.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Function to find symlink target
  2022-05-23  9:05       ` Jean Louis
@ 2022-05-23 20:46         ` Emanuel Berg
  2022-05-24  0:59           ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-05-23 20:46 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>>> S lrwxrwxrwx     1    8 May 22 16:15 test1.pdf -> test.pdf [...]
>>>   -rw-r--r--     1  15K May 22 15:13 test.pdf
>>>
>>> as if I invoke function on first line it will come to ->
>>> test.pdf which is not what I would like.
>> 
>> Right, I see. Okey then, put the search in a loop and upon
>> every hit goto the beginning of the match and do
>> 
>>   (get-text-property (point) 'dired-filename)
>> 
>> this will be true for the third line's test.pdf but not
>> the first.
>
> When I evaluate it, I get t only, I do not understand.
> Tell me more about the idea of finding particular file in
> dired list and placing cursor on it.

Wasn't the problem how to find the right, in this case,
"target.txt" in a situation like this:

/home/incal/test/dired:
  lrwxrwxrwx 1 incal 10 May 23 22:41 target-link.txt -> target.txt
  -rw-r--r-- 1 incal  0 May 23 22:41 target.txt

Search for "target.txt". When you find it, use

  (get-text-property (point) 'dired-filename)

Here it is nil:

  lrwxrwxrwx 1 incal 10 May 23 22:41 target-link.txt -> target.txt
                                                        ^
So search again, here it is t:

  -rw-r--r-- 1 incal  0 May 23 22:41 target.txt
                                     ^

and that's the target you are looking for.

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-23  8:17   ` Jean Louis
@ 2022-05-23 22:49     ` Michael Heerdegen
  2022-05-23 22:57       ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Michael Heerdegen @ 2022-05-23 22:49 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis <bugs@gnu.support> writes:

> Is there maybe some Dired function to jump exactly to specific file
> name?

I have written one so I don't think so.  Maybe it is useful:

#+begin_src emacs-lisp
(defun my-dired-jump-close (file &optional not-this-window)
  "Visit file under point in its dir buffer, resolving symlinks.

Display the buffer in a popup window in this frame when prefix arg
given and in the selected window else."
  (interactive (let ((file-name-at-point (dired-get-filename)))
                 (list (pcase nil
                         ((guard (file-name-directory (dired-get-filename 'verbatim)))
                          file-name-at-point)
                         ((and (let link (file-symlink-p (if (file-directory-p file-name-at-point)
                                                             (directory-file-name file-name-at-point)
                                                           file-name-at-point)))
                               (guard link))
                          (expand-file-name link (file-name-directory file-name-at-point)))
                         (_ file-name-at-point))
                       current-prefix-arg)))
  (select-window
   (let ((split-height-threshold 15))
     (display-buffer (dired-noselect (file-name-directory file))
                     (if not-this-window
                         '((display-buffer-reuse-window display-buffer-pop-up-window)
                           (inhibit-same-window . t)
                           (reusable-frames . nil))
                       '((display-buffer-same-window))))))
  (dired-goto-file
   (if (file-exists-p file) file
     (minibuffer-with-setup-hook (lambda () (goto-char (point-max)))
       (read-file-name "Dired Goto File: " nil nil nil file)))))
#+end_src

I use this key binding:

#+begin_src emacs-lisp
  (define-key dired-mode-map [(control return)] #'my-dired-jump-close)
#+end_src


Michael.




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

* Re: Function to find symlink target
  2022-05-23 22:49     ` Michael Heerdegen
@ 2022-05-23 22:57       ` Emanuel Berg
  2022-05-24  0:59         ` Michael Heerdegen
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-05-23 22:57 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen wrote:

>> Is there maybe some Dired function to jump exactly to
>> specific file name?
>
> I have written one so I don't think so [...]

I wish the same logic could be applied to my own Elisp :)

But you guys agree on one then and we can have that added
to Dired :)

This one seems heavy on the interface and frame/window
sides, but that's maybe necessary?

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-23 20:46         ` Emanuel Berg
@ 2022-05-24  0:59           ` Emanuel Berg
  2022-05-24  1:09             ` Michael Heerdegen
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-05-24  0:59 UTC (permalink / raw)
  To: help-gnu-emacs

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/geh.el

(require 'cl-lib)

(defun dired-find-link-target (link)
  (let*((target (file-truename link))
        (name   (file-name-nondirectory target)) )
    (find-file (file-name-directory target))
    (goto-char (point-min))
    (cl-loop
     while (re-search-forward name (point-max) t)
     do (when (get-text-property (point) 'dired-filename)
          (cl-return) ))
    (goto-char (match-beginning 0)) ))

;; /home/incal/test/dired:
;; lrwxrwxrwx 1 incal 10 May 23 22:41 target-link.txt -> target.txt
;; -rw-r--r-- 1 incal  0 May 23 22:41 target.txt

(dired-find-link-target "~/test/dired/target-link.txt")

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-23 22:57       ` Emanuel Berg
@ 2022-05-24  0:59         ` Michael Heerdegen
  0 siblings, 0 replies; 41+ messages in thread
From: Michael Heerdegen @ 2022-05-24  0:59 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <incal@dataswamp.org> writes:

> This one seems heavy on the interface and frame/window
> sides, but that's maybe necessary?

No, I just copied it from my init file.  I suits my needs.  Just meant
as an example for gutting.

Michael.




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

* Re: Function to find symlink target
  2022-05-24  0:59           ` Emanuel Berg
@ 2022-05-24  1:09             ` Michael Heerdegen
  2022-05-24  2:14               ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Michael Heerdegen @ 2022-05-24  1:09 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <incal@dataswamp.org> writes:

> (defun dired-find-link-target (link)
>   (let*((target (file-truename link))
>         (name   (file-name-nondirectory target)) )
>     (find-file (file-name-directory target))
>     (goto-char (point-min))
>     (cl-loop
>      while (re-search-forward name (point-max) t)
>      do (when (get-text-property (point) 'dired-filename)
>           (cl-return) ))
>     (goto-char (match-beginning 0)) ))

Not wrong - but reinventing wheels: see `dired-jump' and
`dired-goto-file'.

Michael.




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

* Re: Function to find symlink target
  2022-05-24  1:09             ` Michael Heerdegen
@ 2022-05-24  2:14               ` Emanuel Berg
  2022-05-24  2:27                 ` Michael Heerdegen
  2022-05-25  5:05                 ` Jean Louis
  0 siblings, 2 replies; 41+ messages in thread
From: Emanuel Berg @ 2022-05-24  2:14 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen wrote:

>> (defun dired-find-link-target (link)
>>   (let*((target (file-truename link))
>>         (name   (file-name-nondirectory target)) )
>>     (find-file (file-name-directory target))
>>     (goto-char (point-min))
>>     (cl-loop
>>      while (re-search-forward name (point-max) t)
>>      do (when (get-text-property (point) 'dired-filename)
>>           (cl-return) ))
>>     (goto-char (match-beginning 0)) ))
>
> Not wrong - but reinventing wheels: see `dired-jump' and
> `dired-goto-file'.

None of these work ...

(dired-goto-file "~/test/dired/target-link.txt")
(dired-jump "~/test/dired/target-link.txt")

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-24  2:14               ` Emanuel Berg
@ 2022-05-24  2:27                 ` Michael Heerdegen
  2022-05-24  8:04                   ` Emanuel Berg
  2022-05-25  5:05                 ` Jean Louis
  1 sibling, 1 reply; 41+ messages in thread
From: Michael Heerdegen @ 2022-05-24  2:27 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <incal@dataswamp.org> writes:

> >> (defun dired-find-link-target (link)
> >>   (let*((target (file-truename link))
> >>         (name   (file-name-nondirectory target)) )
> >>     (find-file (file-name-directory target))
> >>     (goto-char (point-min))
> >>     (cl-loop
> >>      while (re-search-forward name (point-max) t)
> >>      do (when (get-text-property (point) 'dired-filename)
> >>           (cl-return) ))
> >>     (goto-char (match-beginning 0)) ))
> >
> > Not wrong - but reinventing wheels: see `dired-jump' and
> > `dired-goto-file'.
>
> None of these work ...
>
> (dired-goto-file "~/test/dired/target-link.txt")
> (dired-jump "~/test/dired/target-link.txt")

I didn't say your function will shrink to one line.  It will shrink a
lot, however.  Any necessary information in the docstrings of those.

Michael.




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

* Re: Function to find symlink target
  2022-05-24  2:27                 ` Michael Heerdegen
@ 2022-05-24  8:04                   ` Emanuel Berg
  2022-05-24  8:52                     ` Michael Heerdegen
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-05-24  8:04 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen wrote:

>> (dired-goto-file "~/test/dired/target-link.txt")
>> (dired-jump "~/test/dired/target-link.txt")
>
> I didn't say your function will shrink to one line. It will
> shrink a lot, however. Any necessary information in the
> docstrings of those.

?

But you just said what the OP asked for isn't in Emacs?

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-24  8:04                   ` Emanuel Berg
@ 2022-05-24  8:52                     ` Michael Heerdegen
  2022-05-25  5:54                       ` Michael Heerdegen
  0 siblings, 1 reply; 41+ messages in thread
From: Michael Heerdegen @ 2022-05-24  8:52 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <incal@dataswamp.org> writes:

> But you just said what the OP asked for isn't in Emacs?

Not directly with one command AFAIK.

Michael.




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

* Re: Function to find symlink target
  2022-05-24  2:14               ` Emanuel Berg
  2022-05-24  2:27                 ` Michael Heerdegen
@ 2022-05-25  5:05                 ` Jean Louis
  2022-05-25 22:33                   ` Emanuel Berg
  1 sibling, 1 reply; 41+ messages in thread
From: Jean Louis @ 2022-05-25  5:05 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <incal@dataswamp.org> [2022-05-24 05:15]:
> Michael Heerdegen wrote:
> 
> >> (defun dired-find-link-target (link)
> >>   (let*((target (file-truename link))
> >>         (name   (file-name-nondirectory target)) )
> >>     (find-file (file-name-directory target))
> >>     (goto-char (point-min))
> >>     (cl-loop
> >>      while (re-search-forward name (point-max) t)
> >>      do (when (get-text-property (point) 'dired-filename)
> >>           (cl-return) ))
> >>     (goto-char (match-beginning 0)) ))
> >
> > Not wrong - but reinventing wheels: see `dired-jump' and
> > `dired-goto-file'.
> 
> None of these work ...
> 
> (dired-goto-file "~/test/dired/target-link.txt")
> (dired-jump "~/test/dired/target-link.txt")

Thank you for `dired-jump' as that is what I needed, it works well
now, I can find target of a symlink easily.

(defun rcd-dired-show-symlink-target ()
  "Show target of a symlink."
  (interactive)
  (let ((file (car (dired-get-marked-files))))
    (if (and file (file-symlink-p file))
      (let* ((target (file-truename file))
	     (target-exists (file-exists-p target))
	     (directory (file-name-directory target)))
	(if target-exists
	    (progn
	      (find-file directory)
	      (dired-jump nil target))
	  (message "Target does not exist: %s" target)))
      (message "Not a symlink: %s" file))))

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Function to find symlink target
  2022-05-24  8:52                     ` Michael Heerdegen
@ 2022-05-25  5:54                       ` Michael Heerdegen
  2022-05-27  2:25                         ` Jean Louis
  0 siblings, 1 reply; 41+ messages in thread
From: Michael Heerdegen @ 2022-05-25  5:54 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Not directly with one command AFAIK.

Note that there are different possibilities what the user might expect
in several cases, e.g. if the target is a directory (dired it in the
containing directory or dired it itself?) or if it's a symlink (most of
the time you'll want to see the truename, unless you need to change a
symlink in between) etc.

Michael.




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

* Re: Function to find symlink target
  2022-05-25  5:05                 ` Jean Louis
@ 2022-05-25 22:33                   ` Emanuel Berg
  2022-05-29  2:01                     ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-05-25 22:33 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> Thank you for `dired-jump' as that is what I needed, it
> works well now, I can find target of a symlink easily.
>
> (defun rcd-dired-show-symlink-target ()
>   "Show target of a symlink."
>   (interactive)
>   (let ((file (car (dired-get-marked-files))))
>     (if (and file (file-symlink-p file))
>       (let* ((target (file-truename file))
> 	     (target-exists (file-exists-p target))
> 	     (directory (file-name-directory target)))
> 	(if target-exists
> 	    (progn
> 	      (find-file directory)
> 	      (dired-jump nil target))
> 	  (message "Target does not exist: %s" target)))
>       (message "Not a symlink: %s" file))))

Yes, that works. You can add an optional FILE argument and
only when that's not provided look for the first marked file
or even the file at point which is perhaps more intuitive
since it's only one file ...

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-25  5:54                       ` Michael Heerdegen
@ 2022-05-27  2:25                         ` Jean Louis
  2022-05-27  3:31                           ` Michael Heerdegen
  2022-05-27 14:47                           ` Emanuel Berg
  0 siblings, 2 replies; 41+ messages in thread
From: Jean Louis @ 2022-05-27  2:25 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

* Michael Heerdegen <michael_heerdegen@web.de> [2022-05-25 09:38]:
> Michael Heerdegen <michael_heerdegen@web.de> writes:
> 
> > Not directly with one command AFAIK.
> 
> Note that there are different possibilities what the user might expect
> in several cases, e.g. if the target is a directory (dired it in the
> containing directory or dired it itself?) or if it's a symlink (most of
> the time you'll want to see the truename, unless you need to change a
> symlink in between) etc.

For now I like that new Dired buffer is open with the target to be
located. 

How do you mean to see truename, is it by message?


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Function to find symlink target
  2022-05-27  2:25                         ` Jean Louis
@ 2022-05-27  3:31                           ` Michael Heerdegen
  2022-05-27  8:00                             ` Jean Louis
  2022-05-27 14:47                           ` Emanuel Berg
  1 sibling, 1 reply; 41+ messages in thread
From: Michael Heerdegen @ 2022-05-27  3:31 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis <bugs@gnu.support> writes:

> How do you mean to see truename, is it by message?

Not sure I understand your question.

I meant this case:

  symlink1 -> symlink2 -> file

what would you want to get?  Both seeing FILE or SYMLINK2 could be
useful.

Michael.



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

* Re: Function to find symlink target
  2022-05-27  3:31                           ` Michael Heerdegen
@ 2022-05-27  8:00                             ` Jean Louis
  0 siblings, 0 replies; 41+ messages in thread
From: Jean Louis @ 2022-05-27  8:00 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

* Michael Heerdegen <michael_heerdegen@web.de> [2022-05-27 06:32]:
> Jean Louis <bugs@gnu.support> writes:
> 
> > How do you mean to see truename, is it by message?
> 
> Not sure I understand your question.
> 
> I meant this case:
> 
>   symlink1 -> symlink2 -> file
> 
> what would you want to get?  Both seeing FILE or SYMLINK2 could be
> useful.

Yes, there are complex conditions.

In my case I need `file', the target. I found also `file-chase-links'
function. But that one returns always something, even if file does not
exist, and is not as good as `file-truename' as it would not resolve
parent directories that are symlinks.

(defun rcd-dired-show-symlink-target (&optional file)
  "Show target of a link."
  (interactive)
  (let ((file (or file (car (dired-get-marked-files)))))
    (if (and file (file-symlink-p file))
      (let* ((target (file-chase-links file))
	     (target-exists (file-exists-p target))
	     (directory (file-name-directory target)))
	(if target-exists
	    (progn
	      (find-file directory)
	      (dired-jump nil target))
	  (rcd-warning-message "Target does not exist: %s" target)))
      (rcd-warning-message "Not a symlink: %s" file))))

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Function to find symlink target
  2022-05-27  2:25                         ` Jean Louis
  2022-05-27  3:31                           ` Michael Heerdegen
@ 2022-05-27 14:47                           ` Emanuel Berg
  2022-05-28  6:43                             ` Jean Louis
  1 sibling, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-05-27 14:47 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>>> Not directly with one command AFAIK.
>> 
>> Note that there are different possibilities what the user
>> might expect in several cases, e.g. if the target is
>> a directory (dired it in the containing directory or dired
>> it itself?) or if it's a symlink (most of the time you'll
>> want to see the truename, unless you need to change
>> a symlink in between) etc.
>
> For now I like that new Dired buffer is open with the target
> to be located.
>
> How do you mean to see truename, is it by message?

symlink - avoid but sometimes useful

symlink to directory - avoid avoid but can be useful

symlink to symlink - avoid avoid avoid

add support for avoid avoid avoid? avoid!

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-27 14:47                           ` Emanuel Berg
@ 2022-05-28  6:43                             ` Jean Louis
  2022-05-28 15:29                               ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Jean Louis @ 2022-05-28  6:43 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

Let us say there are 100 websites, there is repository of pictures, videos, files on computer, but one part must be on websites too, then there is website repository on a local computer. Images and files are then linked to website repository on local computer in their corresponding locations, this saving space, then rsync uploads symlinks as real files to web server.

In this case symlinks spare huge hard disk space.

There is no general rule that one should tell to avoid some feature, rather there shall be particular case to consider to see what could be better solution.




Jean



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

* Re: Function to find symlink target
  2022-05-28  6:43                             ` Jean Louis
@ 2022-05-28 15:29                               ` Emanuel Berg
  2022-05-28 15:43                                 ` Emanuel Berg
                                                   ` (2 more replies)
  0 siblings, 3 replies; 41+ messages in thread
From: Emanuel Berg @ 2022-05-28 15:29 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> Let us say there are 100 websites, there is repository of
> pictures, videos, files on computer, but one part must be on
> websites too, then there is website repository on a local
> computer. Images and files are then linked to website
> repository on local computer in their corresponding
> locations, this saving space, then rsync uploads symlinks as
> real files to web server.
>
> In this case symlinks spare huge hard disk space.

Actually a file (size F) and a symlink (size S and 0 < S)
takes F + S while just the file takes F.

How big is a symlink?

$ touch a.txt
$ ln -s a.txt a-sy.txt
$ du -b a-sl.txt
5

5 bytes. The path to a.txt.

The advantage is one can create virtual filesystems on
a file-by-file basis. There are many use cases for that
including the one you mention ...

> There is no general rule that one should tell to avoid some
> feature

The general rule is don't use it unless there is a good
reason to.

> rather there shall be particular case to consider to see
> what could be better solution.

Indeed.

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-28 15:29                               ` Emanuel Berg
@ 2022-05-28 15:43                                 ` Emanuel Berg
  2022-05-28 16:08                                   ` Eli Zaretskii
  2022-05-31  6:27                                 ` Jean Louis
  2022-05-31  6:31                                 ` Jean Louis
  2 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-05-28 15:43 UTC (permalink / raw)
  To: help-gnu-emacs

> How big is a symlink?
>
> $ touch a.txt
> $ ln -s a.txt a-sy.txt
> $ du -b a-sl.txt
> 5
>
> 5 bytes. The path to a.txt
              ^ relative

Yes, if one places the symlink in some another dir than the
target then the size increases.

Observe

$ cd
$ mkdir -p test/sl
$ cd !:2
$ touch a
$ ln -s a b
$ cd
$ ln -s test/sl/a l

then compare

$ du -b test/sl/b
1	test/slb/

$ du -b l
9	l

Lesson: There is a lot of space to save by placing symlinks correctly!

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-28 15:43                                 ` Emanuel Berg
@ 2022-05-28 16:08                                   ` Eli Zaretskii
  2022-05-28 16:46                                     ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Eli Zaretskii @ 2022-05-28 16:08 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Emanuel Berg <incal@dataswamp.org>
> Date: Sat, 28 May 2022 17:43:00 +0200
> 
> > How big is a symlink?
> >
> > $ touch a.txt
> > $ ln -s a.txt a-sy.txt
> > $ du -b a-sl.txt
> > 5
> >
> > 5 bytes. The path to a.txt
>               ^ relative
> 
> Yes, if one places the symlink in some another dir than the
> target then the size increases.
> 
> Observe
> 
> $ cd
> $ mkdir -p test/sl
> $ cd !:2
> $ touch a
> $ ln -s a b
> $ cd
> $ ln -s test/sl/a l
> 
> then compare
> 
> $ du -b test/sl/b
> 1	test/slb/
> 
> $ du -b l
> 9	l
> 
> Lesson: There is a lot of space to save by placing symlinks correctly!

Actually, for short enough symlinks (like shorter than 60 bytes),
there are no disk space savings at all, regardless of the actual
length of the reference target.

You evidently assume that a symlink is stored in some particular way
on disk, but the reality is different from your assumption.  What 'ls'
and 'du' show you is largely an illusion.



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

* Re: Function to find symlink target
  2022-05-28 16:08                                   ` Eli Zaretskii
@ 2022-05-28 16:46                                     ` Emanuel Berg
  2022-05-28 16:55                                       ` Eli Zaretskii
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-05-28 16:46 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:

>> Lesson: There is a lot of space to save by placing
>> symlinks correctly!
>
> Actually, for short enough symlinks (like shorter than 60
> bytes), there are no disk space savings at all, regardless
> of the actual length of the reference target.
>
> You evidently assume that a symlink is stored in some
> particular way on disk, but the reality is different from
> your assumption. What 'ls' and 'du' show you is largely
> an illusion.

Okay, where are they stored then?

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-28 16:46                                     ` Emanuel Berg
@ 2022-05-28 16:55                                       ` Eli Zaretskii
  2022-05-28 17:05                                         ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Eli Zaretskii @ 2022-05-28 16:55 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Emanuel Berg <incal@dataswamp.org>
> Date: Sat, 28 May 2022 18:46:35 +0200
> 
> > You evidently assume that a symlink is stored in some
> > particular way on disk, but the reality is different from
> > your assumption. What 'ls' and 'du' show you is largely
> > an illusion.
> 
> Okay, where are they stored then?

In the spare space of the inode, exactly as with small files.  See

  https://unix.stackexchange.com/questions/609474/actual-content-of-a-symlink-file



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

* Re: Function to find symlink target
  2022-05-28 16:55                                       ` Eli Zaretskii
@ 2022-05-28 17:05                                         ` Emanuel Berg
  0 siblings, 0 replies; 41+ messages in thread
From: Emanuel Berg @ 2022-05-28 17:05 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:

>>> You evidently assume that a symlink is stored in some
>>> particular way on disk, but the reality is different from
>>> your assumption. What 'ls' and 'du' show you is largely
>>> an illusion.
>> 
>> Okay, where are they stored then?
>
> In the spare space of the inode, exactly as with small files. See
>
>   https://unix.stackexchange.com/questions/609474/actual-content-of-a-symlink-file

Interesting, so it should say you can save a lot of spare
inode space if you place your symlinks cleverly! Use ls(1) or
du(1) to find out how big this illusory advantage is ...

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-25 22:33                   ` Emanuel Berg
@ 2022-05-29  2:01                     ` Emanuel Berg
  0 siblings, 0 replies; 41+ messages in thread
From: Emanuel Berg @ 2022-05-29  2:01 UTC (permalink / raw)
  To: help-gnu-emacs

>> (defun rcd-dired-show-symlink-target ()
>>   "Show target of a symlink." [...]
>
> Yes, that works. You can add an optional FILE argument and
> only when that's not provided look for the first marked file
> or even the file at point which is perhaps more intuitive
> since it's only one file ...

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/dired-jump-target.el

(require 'dired)

(defun dired-jump-target (&optional file)
  "Jump to FILE or to the target if a symlink."
  (interactive
   (let ((fls (dired-get-marked-files)))
     (list (if (= 1 (length fls))
               (car fls)
             (thing-at-point 'filename) ))))
  (let*((tgt (file-truename file))
        (dir (file-name-directory tgt)) )
    (when (file-exists-p tgt)
      (find-file dir)
      (dired-jump nil tgt) )))

;; (dired-jump-target "~/mia.txt") ; from Lisp, regular file
;;                     ^ and try interactively with point here
;;
;; (dired-jump-target "~/l") ; symlink
;;                     ^
;; (dired-jump-target "~/xxx") ; nil and NOOP on no file
;;                     ^
;; last, try from dired with one (1) file marked for cases
;; regular/symlink

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-28 15:29                               ` Emanuel Berg
  2022-05-28 15:43                                 ` Emanuel Berg
@ 2022-05-31  6:27                                 ` Jean Louis
  2022-05-31 12:24                                   ` Emanuel Berg
  2022-05-31  6:31                                 ` Jean Louis
  2 siblings, 1 reply; 41+ messages in thread
From: Jean Louis @ 2022-05-31  6:27 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <incal@dataswamp.org> [2022-05-28 18:30]:
> > There is no general rule that one should tell to avoid some
> > feature
> 
> The general rule is don't use it unless there is a good
> reason to.

General rule is that we have no practical use of general rules. ☺️


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Function to find symlink target
  2022-05-28 15:29                               ` Emanuel Berg
  2022-05-28 15:43                                 ` Emanuel Berg
  2022-05-31  6:27                                 ` Jean Louis
@ 2022-05-31  6:31                                 ` Jean Louis
  2022-05-31 12:16                                   ` Emanuel Berg
  2 siblings, 1 reply; 41+ messages in thread
From: Jean Louis @ 2022-05-31  6:31 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <incal@dataswamp.org> [2022-05-28 18:30]:
> Jean Louis wrote:
> 
> > Let us say there are 100 websites, there is repository of
> > pictures, videos, files on computer, but one part must be on
> > websites too, then there is website repository on a local
> > computer. Images and files are then linked to website
> > repository on local computer in their corresponding
> > locations, this saving space, then rsync uploads symlinks as
> > real files to web server.
> >
> > In this case symlinks spare huge hard disk space.
> 
> Actually a file (size F) and a symlink (size S and 0 < S)
> takes F + S while just the file takes F.

Don't know about those calculations. My symlinks point to PDF files
and images, and the order of files in a website directory has to be
replicated on one or more web servers. That is reason why I keep the
order on local computer. Symlinks greatly help in that case, and do
spare the hard disk space.

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Function to find symlink target
  2022-05-31  6:31                                 ` Jean Louis
@ 2022-05-31 12:16                                   ` Emanuel Berg
  2022-06-01  7:43                                     ` Jean Louis
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-05-31 12:16 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>>> Let us say there are 100 websites, there is repository of
>>> pictures, videos, files on computer, but one part must be
>>> on websites too, then there is website repository on
>>> a local computer. Images and files are then linked to
>>> website repository on local computer in their
>>> corresponding locations, this saving space, then rsync
>>> uploads symlinks as real files to web server.
>>>
>>> In this case symlinks spare huge hard disk space.
>> 
>> Actually a file (size F) and a symlink (size S and 0 < S)
>> takes F + S while just the file takes F.
>
> Don't know about those calculations. My symlinks point to
> PDF files and images, and the order of files in a website
> directory has to be replicated on one or more web servers.

A very common use case ...

> That is reason why I keep the order on local computer.

*one

> Symlinks greatly help in that case, and do spare the hard
> disk space.

Compared to duplicating all the files physically on the
local machine?

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-31  6:27                                 ` Jean Louis
@ 2022-05-31 12:24                                   ` Emanuel Berg
  0 siblings, 0 replies; 41+ messages in thread
From: Emanuel Berg @ 2022-05-31 12:24 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>>> There is no general rule that one should tell to avoid
>>> some feature
>> 
>> The general rule is don't use it unless there is a good
>> reason to.
>
> General rule is that we have no practical use of
> general rules.

In theory the rules apply but in practice the application
rules ...

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-05-31 12:16                                   ` Emanuel Berg
@ 2022-06-01  7:43                                     ` Jean Louis
  2022-06-02  0:40                                       ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Jean Louis @ 2022-06-01  7:43 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <incal@dataswamp.org> [2022-05-31 15:32]:
> > Symlinks greatly help in that case, and do spare the hard
> > disk space.
> 
> Compared to duplicating all the files physically on the
> local machine?

Yes, symlinks can be in a different file structure than their actual
files on the hard disk.

For example:

~/hyperscope/1/2/3/my-file.pdf may be in a complex structure of other
documents, maybe in the same directory could be other 200 files, and
file could be related to ABC subject.

Same file in the public_html directory:

~/public_html/www.example.com/files/world/my-file.pdf 

then may give quite different context, different meaning in a different
file structure. And even file name in WWW structure should may become
more meaningful then the actual file name, that is matter of marketing
online. 

Then I use often this command to give me the actual WWW link to the
file provided file is in my public_html directory:

(defun loc ()
  "Locates the files, and if it is in public_html, it constructs the URL"
  (interactive)
  (let* ((files (dired-get-marked-files)))
    (kill-new (with-temp-buffer
		(while files
		  (let* ((file (pop files))
			 (uri (if current-prefix-arg file
				(public-html-rest file))))
		    (insert uri "\n")))
		(buffer-string)))))

If the file is then located in WWW structure, I would do `M-x loc' on
the file and get a result like:

https://www.example.com.com/files/world/2020/04/foundation.pdf

but if file is not located in WWW structure, I would get result like:

~/public_html/www.example.com/files/world/my-file.pdf 

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Function to find symlink target
  2022-06-01  7:43                                     ` Jean Louis
@ 2022-06-02  0:40                                       ` Emanuel Berg
  2022-06-02  5:15                                         ` Jean Louis
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-06-02  0:40 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>>> Symlinks greatly help in that case, and do spare the hard
>>> disk space.
>> 
>> Compared to duplicating all the files physically on the
>> local machine?
>
> Yes, symlinks can be in a different file structure than
> their actual files on the hard disk.
>
> For example [...]

This is the same use case that has been mentioned several
times by now! Maybe that's the only things symlinks are
good for?

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Function to find symlink target
  2022-06-02  0:40                                       ` Emanuel Berg
@ 2022-06-02  5:15                                         ` Jean Louis
  2022-06-05  5:40                                           ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Jean Louis @ 2022-06-02  5:15 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <incal@dataswamp.org> [2022-06-02 03:44]:
> This is the same use case that has been mentioned several
> times by now! Maybe that's the only things symlinks are
> good for?

Maybe you have been following your "rule" to avoid symlinks without
researching what you can do with symlinks.

Main use for symlinks on a GNU system is in libraries' directories:

  lrwxrwxrwx   1    11 May 16  2020 aspell -> aspell-0.60
  lrwxrwxrwx   1    17 Apr 28 12:55 terminfo -> ../share/terminfo
  lrwxrwxrwx 1   22 Mar 25  2021 libauthcustom.so -> libauthcustom.so.0.0.0
  lrwxrwxrwx 1   22 Mar 25  2021 libauthcustom.so.0 -> libauthcustom.so.0.0.0
  -rwxr-xr-x 1  14K Mar 25  2021 libauthcustom.so.0.0.0
  lrwxrwxrwx 1   20 Mar 25  2021 libauthldap.so -> libauthldap.so.0.0.0
  lrwxrwxrwx 1   20 Mar 25  2021 libauthldap.so.0 -> libauthldap.so.0.0.0
  -rwxr-xr-x 1  87K Mar 25  2021 libauthldap.so.0.0.0
  lrwxrwxrwx 1   21 Mar 25  2021 libauthmysql.so -> libauthmysql.so.0.0.0
  lrwxrwxrwx 1   21 Mar 25  2021 libauthmysql.so.0 -> libauthmysql.so.0.0.0
  -rwxr-xr-x 1  75K Mar 25  2021 libauthmysql.so.0.0.0
  lrwxrwxrwx 1   19 Mar 25  2021 libauthpam.so -> libauthpam.so.0.0.0
  lrwxrwxrwx 1   19 Mar 25  2021 libauthpam.so.0 -> libauthpam.so.0.0.0
  -rwxr-xr-x 1  14K Mar 25  2021 libauthpam.so.0.0.0
  lrwxrwxrwx 1   21 Mar 25  2021 libauthpgsql.so -> libauthpgsql.so.0.0.0
  lrwxrwxrwx 1   21 Mar 25  2021 libauthpgsql.so.0 -> libauthpgsql.so.0.0.0
  -rwxr-xr-x 1  63K Mar 25  2021 libauthpgsql.so.0.0.0
  lrwxrwxrwx 1   20 Mar 25  2021 libauthpipe.so -> libauthpipe.so.0.0.0
  lrwxrwxrwx 1   20 Mar 25  2021 libauthpipe.so.0 -> libauthpipe.so.0.0.0
  -rwxr-xr-x 1  14K Mar 25  2021 libauthpipe.so.0.0.0
  lrwxrwxrwx 1   19 Mar 25  2021 libauthpwd.so -> libauthpwd.so.0.0.0
  lrwxrwxrwx 1   19 Mar 25  2021 libauthpwd.so.0 -> libauthpwd.so.0.0.0
  -rwxr-xr-x 1  14K Mar 25  2021 libauthpwd.so.0.0.0
  lrwxrwxrwx 1   22 Mar 25  2021 libauthshadow.so -> libauthshadow.so.0.0.0
  lrwxrwxrwx 1   22 Mar 25  2021 libauthshadow.so.0 -> libauthshadow.so.0.0.0
  -rwxr-xr-x 1  14K Mar 25  2021 libauthshadow.so.0.0.0
  lrwxrwxrwx 1   22 Mar 25  2021 libauthsqlite.so -> libauthsqlite.so.0.0.0
  lrwxrwxrwx 1   22 Mar 25  2021 libauthsqlite.so.0 -> libauthsqlite.so.0.0.0
  -rwxr-xr-x 1  55K Mar 25  2021 libauthsqlite.so.0.0.0
  lrwxrwxrwx 1   22 Mar 25  2021 libauthuserdb.so -> libauthuserdb.so.0.0.0
  lrwxrwxrwx 1   22 Mar 25  2021 libauthuserdb.so.0 -> libauthuserdb.so.0.0.0
  -rwxr-xr-x 1  30K Mar 25  2021 libauthuserdb.so.0.0.0
  lrwxrwxrwx 1   29 Mar 25  2021 libcourierauthcommon.so -> libcourierauthcommon.so.0.0.0
  lrwxrwxrwx 1   29 Mar 25  2021 libcourierauthcommon.so.0 -> libcourierauthcommon.so.0.0.0
  -rwxr-xr-x 1  42K Mar 25  2021 libcourierauthcommon.so.0.0.0
  lrwxrwxrwx 1   33 Mar 25  2021 libcourierauthsaslclient.so -> libcourierauthsaslclient.so.0.0.0
  lrwxrwxrwx 1   33 Mar 25  2021 libcourierauthsaslclient.so.0 -> libcourierauthsaslclient.so.0.0.0
  -rwxr-xr-x 1  14K Mar 25  2021 libcourierauthsaslclient.so.0.0.0
  lrwxrwxrwx 1   27 Mar 25  2021 libcourierauthsasl.so -> libcourierauthsasl.so.0.0.0
  lrwxrwxrwx 1   27 Mar 25  2021 libcourierauthsasl.so.0 -> libcourierauthsasl.so.0.0.0
  -rwxr-xr-x 1  14K Mar 25  2021 libcourierauthsasl.so.0.0.0
  lrwxrwxrwx 1   23 Mar 25  2021 libcourierauth.so -> libcourierauth.so.0.0.0
  lrwxrwxrwx 1   23 Mar 25  2021 libcourierauth.so.0 -> libcourierauth.so.0.0.0

However, I can't tell how is that system managed, it apparently works
fine without my user's intervention.

Here are more practical example on finding files easier in file system
by using symlinks for tagging:

What's a good solution for file-tagging in linux? - Super User
https://superuser.com/questions/81563/whats-a-good-solution-for-file-tagging-in-linux

Another interesting file tagging system:

TMSU
https://tmsu.org/




-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Function to find symlink target
  2022-06-02  5:15                                         ` Jean Louis
@ 2022-06-05  5:40                                           ` Emanuel Berg
  0 siblings, 0 replies; 41+ messages in thread
From: Emanuel Berg @ 2022-06-05  5:40 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> Main use for symlinks on a GNU system is in libraries'
> directories:
>
>   lrwxrwxrwx   1    11 May 16  2020 aspell -> aspell-0.60

This is so you can just refer to - here - aspell and it will
lead you to a specific version, or just the version that is
currently installed.

>   lrwxrwxrwx 1   22 Mar 25  2021 libauthcustom.so -> libauthcustom.so.0.0.0
>   lrwxrwxrwx 1   22 Mar 25  2021 libauthcustom.so.0 -> libauthcustom.so.0.0.0

It has to do with versions as well:

  The symbol versioning is a GNU extension to library
  versioning [that] allows a single externally-versioned
  library (e.g. libc.so.6) to provide multiple incompatible
  implementations of the same symbol (before symbol
  versioning, you had to update the external version of the
  library every time you introduced incompatible interface;
  but with symbol versioning you don't). [1]

> Here are more practical example on finding files easier in
> file system by using symlinks for tagging

I have tagging with my e-mail, you can send a mail to
incal+even@dataswamp.org even ...

Not sure what tagging you refer to tho? Maybe symbolic (or
soft) links are pretty useless, is the disappointing truth?

[1] https://stackoverflow.com/a/20443988

-- 
underground experts united
https://dataswamp.org/~incal




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

end of thread, other threads:[~2022-06-05  5:40 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-18 20:55 Function to find symlink target Jean Louis
2022-05-18 23:00 ` Emanuel Berg
2022-05-22 13:52   ` Jean Louis
2022-05-22 18:02     ` Emanuel Berg
2022-05-23  9:05       ` Jean Louis
2022-05-23 20:46         ` Emanuel Berg
2022-05-24  0:59           ` Emanuel Berg
2022-05-24  1:09             ` Michael Heerdegen
2022-05-24  2:14               ` Emanuel Berg
2022-05-24  2:27                 ` Michael Heerdegen
2022-05-24  8:04                   ` Emanuel Berg
2022-05-24  8:52                     ` Michael Heerdegen
2022-05-25  5:54                       ` Michael Heerdegen
2022-05-27  2:25                         ` Jean Louis
2022-05-27  3:31                           ` Michael Heerdegen
2022-05-27  8:00                             ` Jean Louis
2022-05-27 14:47                           ` Emanuel Berg
2022-05-28  6:43                             ` Jean Louis
2022-05-28 15:29                               ` Emanuel Berg
2022-05-28 15:43                                 ` Emanuel Berg
2022-05-28 16:08                                   ` Eli Zaretskii
2022-05-28 16:46                                     ` Emanuel Berg
2022-05-28 16:55                                       ` Eli Zaretskii
2022-05-28 17:05                                         ` Emanuel Berg
2022-05-31  6:27                                 ` Jean Louis
2022-05-31 12:24                                   ` Emanuel Berg
2022-05-31  6:31                                 ` Jean Louis
2022-05-31 12:16                                   ` Emanuel Berg
2022-06-01  7:43                                     ` Jean Louis
2022-06-02  0:40                                       ` Emanuel Berg
2022-06-02  5:15                                         ` Jean Louis
2022-06-05  5:40                                           ` Emanuel Berg
2022-05-25  5:05                 ` Jean Louis
2022-05-25 22:33                   ` Emanuel Berg
2022-05-29  2:01                     ` Emanuel Berg
2022-05-19 23:14 ` Nick Dokos
2022-05-20  0:42   ` Emanuel Berg
2022-05-23  8:17   ` Jean Louis
2022-05-23 22:49     ` Michael Heerdegen
2022-05-23 22:57       ` Emanuel Berg
2022-05-24  0:59         ` Michael Heerdegen

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.