all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Ivan Kanis <ivan@kanis.fr>
Cc: kfogel@red-bean.com, Emacs Development List <emacs-devel@gnu.org>
Subject: Re: code review request for saveplace with dired buffer
Date: Fri, 07 Jun 2013 15:12:11 -0400	[thread overview]
Message-ID: <jwv8v2l68tp.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87ppvy4e0m.fsf@kanis.fr> (Ivan Kanis's message of "Fri, 07 Jun 2013 08:43:21 +0200")

Thanks Ivan.  See some stylistic comments below, but otherwise, feel
free to install it.


        Stefan


> +(eval-when-compile (require 'saveplace))

I don't see any need for it.  Such a compile-time require is only needed
if you use macros from that package (or if your macros use functions
from that package).

>  ;; FIXME document whatever dired-x is doing.
>  (defun dired-initial-position (dirname)
>    "Where point should go in a new listing of DIRNAME.
> @@ -2762,7 +2765,8 @@ Point assumed at beginning of new subdir line."
>    (end-of-line)
>    (and (featurep 'dired-x) dired-find-subdir
>         (dired-goto-subdir dirname))
> -  (if dired-trivial-filenames (dired-goto-next-nontrivial-file)))
> +  (if dired-trivial-filenames (dired-goto-next-nontrivial-file))
> +  (if (featurep 'saveplace) (save-place-position-dired-cursor)))

Maybe a better alternative is to add a dired-initial-position-hook.
This way dired doesn't need any saveplace-specific code and instead
saveplace can simply add `save-place-position-dired-cursor' to
`dired-initial-position-hook'.

>    ;; file.  If not, do so, then feel free to modify the alist.  It
>    ;; will be saved again when Emacs is killed.
>    (or save-place-loaded (load-save-place-alist-from-file))
> -  (when (and buffer-file-name
> -	     (or (not save-place-ignore-files-regexp)
> -		 (not (string-match save-place-ignore-files-regexp
> -				    buffer-file-name))))
> -    (let ((cell (assoc buffer-file-name save-place-alist))
> -	  (position (if (not (eq major-mode 'hexl-mode))
> -			(point)
> -		      (with-no-warnings
> -			(1+ (hexl-current-address))))))
> -      (if cell
> -	  (setq save-place-alist (delq cell save-place-alist)))
> -      (if (and save-place
> -	       (not (= position 1)))  ;; Optimize out the degenerate case.
> -	  (setq save-place-alist
> -		(cons (cons buffer-file-name position)
> -		      save-place-alist))))))
> +  (let ((item (or buffer-file-name
> +                  (when dired-directory (expand-file-name dired-directory))))
> +        cell position)
> +    (when (and item
> +               (or (not save-place-ignore-files-regexp)
> +                   (not (string-match save-place-ignore-files-regexp
> +                                      item))))
> +      (setq cell (assoc item save-place-alist)
> +            position (if (not (eq major-mode 'hexl-mode))
> +                         (point)
> +                       (with-no-warnings
> +                         (1+ (hexl-current-address)))))

I think it's preferable to keep the cell and position binding in
a separate let.  Two "let"s are more efficient than such a "single let
plus subsequent setqs".  Also they're cleaner since they avoid `setq'.

> There might be a convention of using `when' instead of `if', when

What Glenn said.


        Stefan



  parent reply	other threads:[~2013-06-07 19:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-07  6:43 code review request for saveplace with dired buffer Ivan Kanis
2013-06-07 15:59 ` Karl Fogel
2013-06-07 17:25   ` Glenn Morris
2013-06-07 20:08     ` Drew Adams
2013-06-07 22:20       ` Karl Fogel
2013-06-08  5:09       ` Drew Adams
2013-06-07 19:12 ` Stefan Monnier [this message]
2013-06-09 15:42   ` Ivan Kanis
2013-06-09 16:20     ` Karl Fogel
2013-06-10  7:42       ` Ivan Kanis
2013-06-10 14:00         ` Karl Fogel
2013-06-10 16:35     ` Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv8v2l68tp.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=ivan@kanis.fr \
    --cc=kfogel@red-bean.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.