[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Function to find symlink target
From: |
Emanuel Berg |
Subject: |
Re: Function to find symlink target |
Date: |
Thu, 19 May 2022 01:00:34 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
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
- Function to find symlink target, Jean Louis, 2022/05/18
- Re: Function to find symlink target,
Emanuel Berg <=
- Re: Function to find symlink target, Jean Louis, 2022/05/22
- Re: Function to find symlink target, Emanuel Berg, 2022/05/22
- Re: Function to find symlink target, Jean Louis, 2022/05/23
- Re: Function to find symlink target, Emanuel Berg, 2022/05/23
- Re: Function to find symlink target, Emanuel Berg, 2022/05/23
- Re: Function to find symlink target, Michael Heerdegen, 2022/05/23
- Re: Function to find symlink target, Emanuel Berg, 2022/05/23
- Re: Function to find symlink target, Michael Heerdegen, 2022/05/23
- Re: Function to find symlink target, Emanuel Berg, 2022/05/24
- Re: Function to find symlink target, Michael Heerdegen, 2022/05/24