unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Push mark before jumping to new location in a source code file from help page xref
@ 2012-12-02 20:18 Kelly Dean
  0 siblings, 0 replies; only message in thread
From: Kelly Dean @ 2012-12-02 20:18 UTC (permalink / raw)
  To: emacs-devel

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

When following a link in the help page for a function or variable to open the source code file, and the file is already open, it moves the point in that buffer, but it doesn't push the mark first, so I lose my previous place. It should push the mark first.
The attached patch fixes it.

[-- Attachment #2: patch --]
[-- Type: application/octet-stream, Size: 3183 bytes --]

--- emacs-24.2/lisp/help-mode.el
+++ emacs-24.2/lisp/help-mode.el
@@ -195,11 +195,15 @@
 			   (help-C-file-name (indirect-function fun) 'fun)))
 		   ;; Don't use find-function-noselect because it follows
 		   ;; aliases (which fails for built-in functions).
-		   (let ((location
+		   (let* (help-xref-target-buffer-preexisting
+			 (location
 			  (find-function-search-for-symbol fun nil file)))
 		     (pop-to-buffer (car location))
 		     (if (cdr location)
-			 (goto-char (cdr location))
+			 (progn (if (and (/= (cdr location) (point))
+					 help-xref-target-buffer-preexisting)
+				    (push-mark))
+			  (goto-char (cdr location)))
 		       (message "Unable to find location in file"))))
   'help-echo (purecopy "mouse-2, RET: find function's definition"))
 
@@ -224,10 +228,14 @@
   'help-function (lambda (var &optional file)
 		   (when (eq file 'C-source)
 		     (setq file (help-C-file-name var 'var)))
-		   (let ((location (find-variable-noselect var file)))
+		   (let* (help-xref-target-buffer-preexisting
+			 (location (find-variable-noselect var file)))
 		     (pop-to-buffer (car location))
 		     (if (cdr location)
-		       (goto-char (cdr location))
+			 (progn (if (and (/= (cdr location) (point))
+					 help-xref-target-buffer-preexisting)
+				    (push-mark))
+			  (goto-char (cdr location)))
 		       (message "Unable to find location in file"))))
   'help-echo (purecopy "mouse-2, RET: find variable's definition"))
 
--- emacs-24.2/lisp/emacs-lisp/find-func.el
+++ emacs-24.2/lisp/emacs-lisp/find-func.el
@@ -211,7 +211,9 @@
     (setq fun-or-var (find-function-advised-original
 		      (indirect-function
 		       (find-function-advised-original fun-or-var)))))
-  (with-current-buffer (find-file-noselect file)
+  (if (boundp help-xref-target-buffer-preexisting)
+    (setq help-xref-target-buffer-preexisting (find-buffer-visiting file)))
+  (with-current-buffer (find-file-noselect file) (save-excursion
     (goto-char (point-min))
     (unless (re-search-forward
 	     (if type
@@ -223,7 +225,7 @@
 		       "\""))
 	     nil t)
       (error "Can't find source for %s" fun-or-var))
-    (cons (current-buffer) (match-beginning 0))))
+    (cons (current-buffer) (match-beginning 0)))))
 
 ;;;###autoload
 (defun find-library (library)
@@ -282,7 +284,9 @@
       (setq library (substring library 0 (match-beginning 1))))
     (let* ((filename (find-library-name library))
 	   (regexp-symbol (cdr (assq type find-function-regexp-alist))))
-      (with-current-buffer (find-file-noselect filename)
+      (if (boundp help-xref-target-buffer-preexisting)
+	(setq help-xref-target-buffer-preexisting (find-buffer-visiting filename)))
+      (with-current-buffer (find-file-noselect filename) (save-excursion
 	(let ((regexp (format (symbol-value regexp-symbol)
 			      ;; Entry for ` (backquote) macro in loaddefs.el,
 			      ;; (defalias (quote \`)..., has a \ but
@@ -310,7 +314,7 @@
 		(progn
 		  (beginning-of-line)
 		  (cons (current-buffer) (point)))
-	      (cons (current-buffer) nil))))))))
+	      (cons (current-buffer) nil)))))))))
 
 ;;;###autoload
 (defun find-function-noselect (function &optional lisp-only)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-12-02 20:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-02 20:18 [PATCH] Push mark before jumping to new location in a source code file from help page xref Kelly Dean

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