* How do i say it in emacs lisp [not found] ` <CAPzsW6gvO4jExpo=V5vyu+Zw+04nL808sJwLwVnOrFKkj16zWQ@mail.gmail.com> @ 2016-11-27 20:46 ` Matthias Pfeifer 2016-11-28 9:21 ` tomas 0 siblings, 1 reply; 5+ messages in thread From: Matthias Pfeifer @ 2016-11-27 20:46 UTC (permalink / raw) To: help-gnu-emacs Hi there, I want to say this in emacs lisp Whenever the buffer in the selected window Is changed, do something in a certain other window (which displays a certain well known buffer) Is this possible? How would it be done? Matthias ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How do i say it in emacs lisp 2016-11-27 20:46 ` How do i say it in emacs lisp Matthias Pfeifer @ 2016-11-28 9:21 ` tomas 2016-11-28 11:50 ` Matthias Pfeifer 0 siblings, 1 reply; 5+ messages in thread From: tomas @ 2016-11-28 9:21 UTC (permalink / raw) To: Matthias Pfeifer; +Cc: help-gnu-emacs -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sun, Nov 27, 2016 at 09:46:49PM +0100, Matthias Pfeifer wrote: > Hi there, > > I want to say this in emacs lisp > > Whenever the buffer in the selected window > Is changed, do something in a certain other window (which displays a > certain well known buffer) > > Is this possible? How would it be done? Yes. Since your question is pretty unspecific, I'll assume you'd like to be pointed in a general direction. Here it goes: Emacs's way of extending functionality "whenever something happens" is typically called "hooks": you can insert a function of yours to be called whenever "something" happens. The hooks you are looking for are described in the Emacs Lisp manual (31.28, Change hooks [1]). There, you have to decide whether you want to be called before or after the text change happens (there are two aptly named hooks). To get the ball rolling, here's minimal code which complains at every change in a buffer: (add-hook 'after-change-functions (lambda (beg end oldlen) (message (format "Ouch: beg=%S end=%S oldlen=%S" beg end oldlen))) nil t) Insert it in a buffer in lisp mode (e.g. your *scratch* buffer, if your Emacs is set up in a "normal" way, type C-x C-e to get the hook function inseerted and watch the action whenever you modify the buffer. The "t" at the end sets the hook locally, i.e. only for the local buffer. Do come back if you have further questions! regards [1] Or online, at https://www.gnu.org/software/emacs/manual/html_node/elisp/Change-Hooks.html - -- tomás -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlg79vwACgkQBcgs9XrR2kZofACfdhy4Lr6bB88PgToGEZr3Bcg1 La4Anij3GKm97u6y+FpadyBgV/HfZxEN =xwDi -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How do i say it in emacs lisp 2016-11-28 9:21 ` tomas @ 2016-11-28 11:50 ` Matthias Pfeifer 2016-11-28 20:12 ` tomas 2016-12-21 18:19 ` Thien-Thi Nguyen 0 siblings, 2 replies; 5+ messages in thread From: Matthias Pfeifer @ 2016-11-28 11:50 UTC (permalink / raw) To: help-gnu-emacs@gnu.org Hi Tomas, thanks for the general clarification. I was suspecting hooks to be the way to go. However I was running in some sort of recursion (i guess) until i figured out to temporarily set my hook to nil. This is what I fiddled together: My plan is to have a package called "neotree" update it's buffer whenever another window's buffer is switched and the selected frame's configuration matches a certain layout. Let me try to re-phrase: When the current frame hosts two windows. And any of these windows is showing the neotree buffer and other window's buffers is switched then I want neotree to go to the buffers file. Here is my elisp: (defun mp:neotree-updater () (when (eq 2 (length (window-list))) (let* ((wnd-0 (nth 0 (window-list))) (wnd-1 (nth 1 (window-list))) (buf-0 (window-buffer wnd-0)) (buf-1 (window-buffer wnd-1)) (neo-buf nil) (other-buf nil) (neo-wnd nil) (other-wnd nil) (filename nil) (neo-buffer (get-buffer " *NeoTree*"))) (when (and neo-buffer (or (eq buf-0 neo-buffer) (eq buf-1 neo-buffer))) (progn (if (eq buf-0 neo-global--buffer) (setq neo-buf buf-0 other-buf buf-1 neo-wnd wnd-0 other-wnd wnd-1) (setq neo-buf buf-1 other-buf buf-0 neo-wnd wnd-1 other-wnd wnd-0)) (setq filename (buffer-file-name other-buf)) (when (and filename (file-exists-p filename)) (progn (setq mp:neotree-go-to-dir filename) (let ((buffer-list-update-hook buffer-list-update-hook)) (neotree-find filename) (select-window other-wnd))))))))) ;; (add-hook 'buffer-list-update-hook 'mp:neotree-updater) ;; (remove-hook 'buffer-list-update-hook 'mp:neotree-updater) It seems to be working the way I expected it. Second opinion is welcome :-) Matthias Pfeifer ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How do i say it in emacs lisp 2016-11-28 11:50 ` Matthias Pfeifer @ 2016-11-28 20:12 ` tomas 2016-12-21 18:19 ` Thien-Thi Nguyen 1 sibling, 0 replies; 5+ messages in thread From: tomas @ 2016-11-28 20:12 UTC (permalink / raw) To: Matthias Pfeifer; +Cc: help-gnu-emacs@gnu.org -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, Nov 28, 2016 at 11:50:32AM +0000, Matthias Pfeifer wrote: > Hi Tomas, > > > thanks for the general clarification [...] Glad it helped. I'll have to save your code for the weekend. timeis a bit tight ATM. But it looks interesting. To enhance your chances of a review, it'd help if you described in human language what it's supposed to do (for example: does your code expect that there are *exactly* two windows? Why?). Lisp on :-) regards - -- t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlg8j6UACgkQBcgs9XrR2kZyBQCfZvZ6oz4ikfM2UlYaFXWEtH3h R48An0UfclFcjXKwMt2G8nlcT53i99ch =/JNI -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How do i say it in emacs lisp 2016-11-28 11:50 ` Matthias Pfeifer 2016-11-28 20:12 ` tomas @ 2016-12-21 18:19 ` Thien-Thi Nguyen 1 sibling, 0 replies; 5+ messages in thread From: Thien-Thi Nguyen @ 2016-12-21 18:19 UTC (permalink / raw) To: Matthias Pfeifer; +Cc: help-gnu-emacs@gnu.org [-- Attachment #1: Type: text/plain, Size: 1367 bytes --] () Matthias Pfeifer <matthias-pfeifer@outlook.com> () Mon, 28 Nov 2016 11:50:32 +0000 Second opinion is welcome :-) Cool. (let* (... (neo-buf nil) (other-buf nil) (neo-wnd nil) (other-wnd nil) (filename nil) ...) You can write these w/o the ‘nil’ and even w/o the per-var parens. Conventionally, such vars are grouped at the end of the ‘let’ VARLIST block, e.g.: (let* ((v1 1) (v2 2) v3 v4 v5) ...). (when (and neo-buffer (or (eq buf-0 neo-buffer) (eq buf-1 neo-buffer))) presuming ‘buf-0’ and ‘buf-1’ are never nil, you can use ‘memq’: (when (memq neo-buffer (list buf-0 buf-1)) This constructs a list and discards it after the ‘memq’ so maybe not too indicated if gratuitous garbage goes against your grain. (progn This is superfluous; (when (progn ...)) ≡ (when ...) in meaning. Same goes for the other ‘progn’. -- Thien-Thi Nguyen ----------------------------------------------- (defun responsep (type via) (case type (technical (eq 'mailing-list via)) ...)) 748E A0E8 1CB8 A748 9BFA --------------------------------------- 6CE4 6703 2224 4C80 7502 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 197 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-12-21 18:19 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <CAPzsW6jZpzKKfy3u0tghOQgeZM9qOoLBH3U5EDpjOFB9GwNHXQ@mail.gmail.com> [not found] ` <CAPzsW6i3UHiAyWFGKrf=pa3B91ZFqgnAT2+vmg=S-agCRi7vZg@mail.gmail.com> [not found] ` <CAPzsW6j+8W+i0t_CvDz0BEa6diG+z7YiDi7rJfsiknbLYmK3=A@mail.gmail.com> [not found] ` <CAPzsW6jdmQkqQwA7wPaPNEA4Ayef7Vm+s1jxVH_Z4zHCWKLyMg@mail.gmail.com> [not found] ` <CAPzsW6hrvFGVyodjd5Zg83-8ZE3s94EDfv28NQRWoRszOoUPKg@mail.gmail.com> [not found] ` <CAPzsW6j2iip9LbqC4zs2g39yvS-VpT-bm0cnhUL3arxC1va7_Q@mail.gmail.com> [not found] ` <CAPzsW6jx0LcsPaTmdoLBjgJSAOw_ytk7e4YqGpo+UwA7+Ou7mA@mail.gmail.com> [not found] ` <CAPzsW6gvO4jExpo=V5vyu+Zw+04nL808sJwLwVnOrFKkj16zWQ@mail.gmail.com> 2016-11-27 20:46 ` How do i say it in emacs lisp Matthias Pfeifer 2016-11-28 9:21 ` tomas 2016-11-28 11:50 ` Matthias Pfeifer 2016-11-28 20:12 ` tomas 2016-12-21 18:19 ` Thien-Thi Nguyen
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.