Skip to main content
added 1 character in body
Source Link

I would like to make set-window-dedicated-p a NOP when called from xref--show-pos-in-buf. Below is an attempt to do so using advice. It doesn't work, I think because fset is not really copying the original function definition, just pointing things at each other. How can I either fix this approach to make it work, or use an alternative approach to accomplish my overall goal?

Overall goal: The way I have things set up, when I run an xref command like xref-find-references, buffer *xref* is shown in a full window which is how I like. But, when I hit RET to visit a reference, the location opens in a new frame. From what I can tell, this is because xref--show-pos-in-buf dedicates *xref* which seems to cause display-buffer to think the best solution is to display the buffer in a new frame. I never want a new frame, so my overall goal here is that *xref* and anything I select in it always open in the same frame I am already using.

(defun sham-set-window-dedicated-p (win flag)
  "Don't dedicate WIN, only return FLAG."
  flag)

(fset 'original-set-window-dedicated-p (symbol-function 'set-window-dedicated-p))

(defadvice xref--show-pos-in-buf (around my-xref--show-pos-in-buf activate)
  "Monkey patch set-window-dedicated-p so it doesn't do anything."
  (fset 'set-window-dedicated-p sham-set-window-dedicated-p))
  ad-do-it
  (fset set'set-window-dedicated-p (symbol-function 'original-set-window-dedicated-p)))

I would like to make set-window-dedicated-p a NOP when called from xref--show-pos-in-buf. Below is an attempt to do so using advice. It doesn't work, I think because fset is not really copying the original function definition, just pointing things at each other. How can I either fix this approach to make it work, or use an alternative approach to accomplish my overall goal?

Overall goal: The way I have things set up, when I run an xref command like xref-find-references, buffer *xref* is shown in a full window which is how I like. But, when I hit RET to visit a reference, the location opens in a new frame. From what I can tell, this is because xref--show-pos-in-buf dedicates *xref* which seems to cause display-buffer to think the best solution is to display the buffer in a new frame. I never want a new frame, so my overall goal here is that *xref* and anything I select in it always open in the same frame I am already using.

(defun sham-set-window-dedicated-p (win flag)
  "Don't dedicate WIN, only return FLAG."
  flag)

(fset 'original-set-window-dedicated-p (symbol-function 'set-window-dedicated-p))

(defadvice xref--show-pos-in-buf (around my-xref--show-pos-in-buf activate)
  "Monkey patch set-window-dedicated-p so it doesn't do anything."
  (fset 'set-window-dedicated-p sham-set-window-dedicated-p))
  ad-do-it
  (fset set-window-dedicated-p (symbol-function 'original-set-window-dedicated-p)))

I would like to make set-window-dedicated-p a NOP when called from xref--show-pos-in-buf. Below is an attempt to do so using advice. It doesn't work, I think because fset is not really copying the original function definition, just pointing things at each other. How can I either fix this approach to make it work, or use an alternative approach to accomplish my overall goal?

Overall goal: The way I have things set up, when I run an xref command like xref-find-references, buffer *xref* is shown in a full window which is how I like. But, when I hit RET to visit a reference, the location opens in a new frame. From what I can tell, this is because xref--show-pos-in-buf dedicates *xref* which seems to cause display-buffer to think the best solution is to display the buffer in a new frame. I never want a new frame, so my overall goal here is that *xref* and anything I select in it always open in the same frame I am already using.

(defun sham-set-window-dedicated-p (win flag)
  "Don't dedicate WIN, only return FLAG."
  flag)

(fset 'original-set-window-dedicated-p (symbol-function 'set-window-dedicated-p))

(defadvice xref--show-pos-in-buf (around my-xref--show-pos-in-buf activate)
  "Monkey patch set-window-dedicated-p so it doesn't do anything."
  (fset 'set-window-dedicated-p sham-set-window-dedicated-p))
  ad-do-it
  (fset 'set-window-dedicated-p (symbol-function 'original-set-window-dedicated-p)))
Source Link

Monkey patch and restore builtin set-window-dedicated-p during advice

I would like to make set-window-dedicated-p a NOP when called from xref--show-pos-in-buf. Below is an attempt to do so using advice. It doesn't work, I think because fset is not really copying the original function definition, just pointing things at each other. How can I either fix this approach to make it work, or use an alternative approach to accomplish my overall goal?

Overall goal: The way I have things set up, when I run an xref command like xref-find-references, buffer *xref* is shown in a full window which is how I like. But, when I hit RET to visit a reference, the location opens in a new frame. From what I can tell, this is because xref--show-pos-in-buf dedicates *xref* which seems to cause display-buffer to think the best solution is to display the buffer in a new frame. I never want a new frame, so my overall goal here is that *xref* and anything I select in it always open in the same frame I am already using.

(defun sham-set-window-dedicated-p (win flag)
  "Don't dedicate WIN, only return FLAG."
  flag)

(fset 'original-set-window-dedicated-p (symbol-function 'set-window-dedicated-p))

(defadvice xref--show-pos-in-buf (around my-xref--show-pos-in-buf activate)
  "Monkey patch set-window-dedicated-p so it doesn't do anything."
  (fset 'set-window-dedicated-p sham-set-window-dedicated-p))
  ad-do-it
  (fset set-window-dedicated-p (symbol-function 'original-set-window-dedicated-p)))