* window-other.el / ref-lines.el
@ 2023-01-15 13:11 Emanuel Berg
2023-01-17 17:04 ` [External] : " Drew Adams
0 siblings, 1 reply; 4+ messages in thread
From: Emanuel Berg @ 2023-01-15 13:11 UTC (permalink / raw)
To: help-gnu-emacs
(Pst, I don't know if "with other window" is a good idea,
anyway it should then be called IN other window ... BTW, what
does this (declare (indent 1) (debug t)) do?)
;;; -*- lexical-binding: t -*-
;;
;; this file:
;; https://dataswamp.org/~incal/emacs-init/window-other.el
(defun next-window-buffer ()
(window-buffer (next-window)) )
(defmacro with-other-window (&rest body)
(declare (indent 1) (debug t))
`(let ((buf (next-window-buffer)))
(when (bufferp buf)
(with-current-buffer buf
,@body) )))
(defun apply-in-other-window (fn &rest args)
(let ((buf (next-window-buffer)))
(when (bufferp buf)
(with-current-buffer buf
(apply fn args) ))))
(provide 'window-other)
;;; -*- lexical-binding: t -*-
;;
;; this file:
;; https://dataswamp.org/~incal/emacs-init/ref-lines.el
(require 'window-other)
(defun ref-lines-ref ()
(pcase-let ((`(,beg ,end) (if (use-region-p)
(list (line-number-at-pos (region-beginning))
(line-number-at-pos (region-end)) )
(list (line-number-at-pos) nil) )))
(if (and end (< beg end))
(format "lines %d-%d" beg end)
(format "line %d" beg) )))
(defun ref-lines (&optional other-win no-insert)
(interactive "P")
(let ((ref (if other-win
(apply-in-other-window #'ref-lines-ref)
(ref-lines-ref) )))
(when ref
(if no-insert
(prog1
ref
(message ref) )
(insert ref) ))))
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [External] : window-other.el / ref-lines.el
2023-01-15 13:11 window-other.el / ref-lines.el Emanuel Berg
@ 2023-01-17 17:04 ` Drew Adams
2023-01-17 21:41 ` Emanuel Berg
2023-01-18 18:09 ` FW: " Drew Adams
0 siblings, 2 replies; 4+ messages in thread
From: Drew Adams @ 2023-01-17 17:04 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs@gnu.org
> (defun next-window-buffer ()
> (window-buffer (next-window)) )
>
> (defmacro with-other-window (&rest body)
> (declare (indent 1) (debug t))
> `(let ((buf (next-window-buffer)))
> (when (bufferp buf)
> (with-current-buffer buf
> ,@body) )))
Your macro _name_ is misleading (and so would
be `in-other-window'). You're doing BODY with
the next-window's _buffer current_. But you're
not _selecting_ the next-window while doing it.
IOW, that window isn't selected when you do BODY.
`with-selected-window' does its BODY with
its WINDOW selected. You could (if that were
what you wanted) define a `with-other-window'
which did the equivalent for the `next-window':
(defmacro with-other-window (&rest body)
`(with-selected-window (next-window) ,@body))
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [External] : window-other.el / ref-lines.el
2023-01-17 17:04 ` [External] : " Drew Adams
@ 2023-01-17 21:41 ` Emanuel Berg
2023-01-18 18:09 ` FW: " Drew Adams
1 sibling, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2023-01-17 21:41 UTC (permalink / raw)
To: help-gnu-emacs
Drew Adams wrote:
> `with-selected-window' does its BODY with its WINDOW
> selected. You could (if that were what you wanted) define
> a `with-other-window' which did the equivalent for the
> `next-window':
>
> (defmacro with-other-window (&rest body)
> `(with-selected-window (next-window) ,@body))
Okay, absolutely, didn't know of `with-selected-window' ...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 4+ messages in thread
* FW: [External] : window-other.el / ref-lines.el
2023-01-17 17:04 ` [External] : " Drew Adams
2023-01-17 21:41 ` Emanuel Berg
@ 2023-01-18 18:09 ` Drew Adams
1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2023-01-18 18:09 UTC (permalink / raw)
To: 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'
[-- Attachment #1: Type: text/plain, Size: 1111 bytes --]
Forwarding to the list. Apparently some msgs
I send to Emmanuel and the list don't end up
on the list.
-----Original Message-----
Sent: Tuesday, January 17, 2023 9:05 AM
To: Emanuel Berg <incal@dataswamp.org>; help-gnu-emacs@gnu.org
Subject: RE: [External] : window-other.el / ref-lines.el
> (defun next-window-buffer ()
> (window-buffer (next-window)) )
>
> (defmacro with-other-window (&rest body)
> (declare (indent 1) (debug t))
> `(let ((buf (next-window-buffer)))
> (when (bufferp buf)
> (with-current-buffer buf
> ,@body) )))
Your macro _name_ is misleading (and so would
be `in-other-window'). You're doing BODY with
the next-window's _buffer current_. But you're
not _selecting_ the next-window while doing it.
IOW, that window isn't selected when you do BODY.
`with-selected-window' does its BODY with
its WINDOW selected. You could (if that were
what you wanted) define a `with-other-window'
which did the equivalent for the `next-window':
(defmacro with-other-window (&rest body)
`(with-selected-window (next-window) ,@body))
[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 13816 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-18 18:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-15 13:11 window-other.el / ref-lines.el Emanuel Berg
2023-01-17 17:04 ` [External] : " Drew Adams
2023-01-17 21:41 ` Emanuel Berg
2023-01-18 18:09 ` FW: " Drew Adams
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).