unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* code review request for saveplace with dired buffer
@ 2013-06-07  6:43 Ivan Kanis
  2013-06-07 15:59 ` Karl Fogel
  2013-06-07 19:12 ` Stefan Monnier
  0 siblings, 2 replies; 12+ messages in thread
From: Ivan Kanis @ 2013-06-07  6:43 UTC (permalink / raw)
  To: Emacs Development List; +Cc: kfogel, Stefan Monnier

[-- Attachment #1: Type: text/plain, Size: 315 bytes --]

I have attached the patch for saveplace with dired. Let me know if it's
good to be pushed.

I had to modify dired.el a bit. I thought I could move the cursor using
one of dired hook. Unfortunately it moves the cursor after it called its
hooks.
-- 
Recursivity. Call back if it happens again.
    -- BOFH excuse #36

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: saveplace-dired.patch --]
[-- Type: text/x-diff, Size: 4082 bytes --]

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index bec5a55..1cdec70 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2013-06-99  Ivan Kanis <ivan@kanis.fr>
+	Add support for dired in saveplace.
+	* dired.el (dired-initial-position): Call cursor motion in
+	saveplace.
+	* saveplace.el (save-place-to-alist): Add dired position
+	(save-place-position-dired-cursor): New function
+
 2013-06-05  Leo Liu  <sdl.web@gmail.com>
 
 	Re-implement smie matching block highlight using
diff --git a/lisp/dired.el b/lisp/dired.el
index 5b6a787..84f2be7 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2755,6 +2755,9 @@ as returned by `dired-get-filename'.  LIMIT is the search limit."
 
 (defvar dired-find-subdir)
 
+;; saveplace support
+(eval-when-compile (require 'saveplace))
+
 ;; 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)))
 \f
 ;; These are hooks which make tree dired work.
 ;; They are in this file because other parts of dired need to call them.
diff --git a/lisp/saveplace.el b/lisp/saveplace.el
index 1b7efce..d4af2bc 100644
--- a/lisp/saveplace.el
+++ b/lisp/saveplace.el
@@ -169,22 +169,25 @@ file:
   ;; 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)))))
+      (when cell
+        (setq save-place-alist (delq cell save-place-alist)))
+      (when (and save-place
+                 (not (= position 1)))  ;; Optimize out the degenerate case.
+        (setq save-place-alist
+              (cons (cons item position)
+                    save-place-alist))))))
 
 (defun save-place-forget-unreadable-files ()
   "Remove unreadable files from `save-place-alist'.
@@ -300,6 +303,17 @@ may have changed\) back to `save-place-alist'."
           ;; and make sure it will be saved again for later
           (setq save-place t)))))
 
+(defun save-place-position-dired-cursor ()
+  "Position the cursor in a dired buffer."
+  (or save-place-loaded (load-save-place-alist-from-file))
+  (let ((cell (assoc (expand-file-name dired-directory) save-place-alist)))
+    (if cell
+	(progn
+	  (or revert-buffer-in-progress-p
+	      (goto-char (cdr cell)))
+          ;; and make sure it will be saved again for later
+          (setq save-place t)))))
+
 (defun save-place-kill-emacs-hook ()
   ;; First update the alist.  This loads the old save-place-file if nec.
   (save-places-to-alist)

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

end of thread, other threads:[~2013-06-10 16:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).