pointback.el 0.1 -- Restore window points when returning to buffers

View: New views
3 Messages — Rating Filter:   Alert me  

pointback.el 0.1 -- Restore window points when returning to buffers

by Markus Triska-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Project page:

   http://stud4.tuwien.ac.at/~e0225855/pointback/pointback.html

Code:

;;; pointback.el --- Restore window points when returning to buffers

;; Copyright (C) 2009  Markus Triska

;; Author: Markus Triska <markus.triska@...>
;; Keywords: convenience

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; When you have two windows X and Y showing different sections of the
;; same buffer B, then open a different buffer in X, and then do C-x b
;; to show B in X again, the new point in X will be the same as in Y.
;; With pointback-mode, window points are preserved instead, and point
;; will be where it originally was in X for B when you return to B.

;; Use M-x pointback-mode RET to enable pointback-mode for a buffer.
;; Use M-x global-pointback-mode RET to enable it for all buffers.

;;; Code:

(require 'assoc)

(defconst pointback-version "0.1")

(defvar pointback-windows nil
  "Association list of windows to buffers and window points.")

(defun pointback-store-point ()
  "Save window point for the current buffer of the selected window."
  (let* ((buffers (cdr (assq (selected-window) pointback-windows)))
         (b (assq (current-buffer) buffers)))
    (if b
        (setcdr b (point))
      (let ((current (cons (current-buffer) (window-point))))
        (aput 'pointback-windows (selected-window) (cons current buffers))))))

(defun pointback-restore ()
  "Restore previously stored window point for the selected window."
  (let* ((buffers (cdr (assq (selected-window) pointback-windows)))
         (b (assq (current-buffer) buffers)))
    (when b
      (goto-char (cdr b))))
  ;; delete dead windows from pointback-windows
  (dolist (w pointback-windows)
    (unless (window-live-p (car w))
      (adelete 'pointback-windows (car w))))
  ;; delete window points of dead buffers
  (dolist (w pointback-windows)
    (let (buffers)
      (dolist (b (cdr w))
        (when (buffer-live-p (car b))
          (push b buffers)))
      (aput 'pointback-windows (car w) buffers))))

;;;###autoload
(define-minor-mode pointback-mode
  "Restore previous window point when switching back to a buffer."
  :lighter ""
  (if pointback-mode
      (progn
        (add-hook 'post-command-hook 'pointback-store-point nil t)
        (add-hook 'window-configuration-change-hook
                  'pointback-restore nil t))
    (remove-hook 'post-command-hook 'pointback-store-point t)
    (remove-hook 'window-configuration-change-hook 'pointback-restore t)
    (setq pointback-windows nil)))

;;;###autoload
(define-globalized-minor-mode global-pointback-mode pointback-mode pointback-on)

(defun pointback-on ()
  (pointback-mode 1))

(provide 'pointback)
;;; pointback.el ends here
_______________________________________________
gnu-emacs-sources mailing list
gnu-emacs-sources@...
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources

Xemacs compatibility (was: pointback.el 0.1 -- Restore window points when returning to buffers)

by Uwe Brauer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> "Markus" == Markus Triska <markus.triska@...> writes:

   > Project page:

   >    http://stud4.tuwien.ac.at/~e0225855/pointback/pointback.html

Hi tanks for this code it looks quite interesting.
When I try to compile it under Xemacs 21.4.21 Mule I obtain.

While compiling the end of the data:
  ** the function define-globalized-minor-mode is not known to be defined.

The problem is Xemacs uses quite an old easy-mmode.el

    -  Marcus: do you really need that function?

    -  Xemacs team, can't we upgrade easy-mmode? Or do you we have an
       gpl 3 issue here? I just tried to use easy-mmode from GNU emacs
       22.1 and can't compile it since I obtain
  ** the function set-char-table-parent is not known to be defined.
And that seems to be an built in C function :'(
any ideas what to do?



Uwe Brauer



_______________________________________________
gnu-emacs-sources mailing list
gnu-emacs-sources@...
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources

Re: Xemacs compatibility

by Andreas Röhler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Uwe Brauer wrote:

>>>>>> "Markus" == Markus Triska <markus.triska@...> writes:
>>>>>>            
>
>    > Project page:
>
>    >    http://stud4.tuwien.ac.at/~e0225855/pointback/pointback.html
>
> Hi tanks for this code it looks quite interesting.
> When I try to compile it under Xemacs 21.4.21 Mule I obtain.
>
> While compiling the end of the data:
>   ** the function define-globalized-minor-mode is not known to be defined.
>  

Hi Uwe,

commenting out that line

;; (define-globalized-minor-mode global-pointback-mode pointback-mode
pointback-on)

it works for me with

XEmacs 21.5  (beta28) "fuki" (+CVS-20070806) [Lucid] (i386-suse-linux,
Mule) of Thu Jan 24 2008 on molitor

Cheers

Andreas

--
https://code.launchpad.net/s-x-emacs-werkstatt/
http://bazaar.launchpad.net/~a-roehler/python-mode/python-mode.el/

> The problem is Xemacs uses quite an old easy-mmode.el
>
>     -  Marcus: do you really need that function?
>
>     -  Xemacs team, can't we upgrade easy-mmode? Or do you we have an
>        gpl 3 issue here? I just tried to use easy-mmode from GNU emacs
>        22.1 and can't compile it since I obtain
>   ** the function set-char-table-parent is not known to be defined.
> And that seems to be an built in C function :'(
> any ideas what to do?
>
>
>
> Uwe Brauer
>
>
>
> _______________________________________________
> gnu-emacs-sources mailing list
> gnu-emacs-sources@...
> http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources
>
>  



_______________________________________________
gnu-emacs-sources mailing list
gnu-emacs-sources@...
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources