Skip to main content
deleted 6 characters in body
Source Link
tarsius
  • 26.8k
  • 4
  • 76
  • 115

This seems unfortunate in that, in order to produce a similar effect, it's necessary to copy-paste code: [...] I can copy ansi-term's interactive form

On the contrary, I think it would be a good idea to copy-paste the interactive form of the advised function, even though you don't actually have to do so here.

I read you question from top to bottom. When I got to the code-block I guessed that your advise probably is changing the buffer name. But I didn't know until you later provided the signature as a comment.

In the case under discussion, it appears impossible for the advice author to pass ansi-term only a buffer name, because it's not possible to construct a list which has a value in position 1 but nothing, not even nil, in position 0.

Indeed nothing is less nothing than nothing. :-) But that's hardly relevant here.

As you can see in the documentation you quoted, the value returned by the advice is used as the arguments to the advised function. The return value has to be a list of all arguments not just the ones that have changed.

Staying as close as possible to the old advise, this is what you would have to do using nadvice:

(defun ansi-term--tag-buffer (&rest args) ;; As npostavs pointed out we also have to make sure the list is ;; two elements long. Which makes this approach even more undesirable. (when (= (length args) 1) (setq args (nconc args (list nil)))) (let ((name (read-from-minibuffer "Tag: "))) (and (not (string= name "")) (setf (nth 1 args) (concat "Term: " name)))) args) (advice-add 'ansi-term :filter-args 'ansi-term--tag-buffer) 

But I recommend you define the advice like this instead:

(defun ansi-term--tag-buffer (program &optional buffer-name) (list program (let ((tag (read-from-minibuffer "Tag: "))) (if (string= tag "") buffer-name (concat "Term: " tag))))) 

This variant actually is self-explanatory.

This seems unfortunate in that, in order to produce a similar effect, it's necessary to copy-paste code: [...] I can copy ansi-term's interactive form

On the contrary, I think it would be a good idea to copy-paste the interactive form of the advised function, even though you don't actually have to do so here.

I read you question from top to bottom. When I got to the code-block I guessed that your advise probably is changing the buffer name. But I didn't know until you later provided the signature as a comment.

In the case under discussion, it appears impossible for the advice author to pass ansi-term only a buffer name, because it's not possible to construct a list which has a value in position 1 but nothing, not even nil, in position 0.

Indeed nothing is less nothing than nothing. :-) But that's hardly relevant here.

As you can see in the documentation you quoted, the value returned by the advice is used as the arguments to the advised function. The return value has to be a list of all arguments not just the ones that have changed.

Staying as close as possible to the old advise, this is what you would have to do using nadvice:

(defun ansi-term--tag-buffer (&rest args) ;; As npostavs pointed out we also have to make sure the list is ;; two elements long. Which makes this approach even more undesirable. (when (= (length args) 1) (setq args (nconc args (list nil)))) (let ((name (read-from-minibuffer "Tag: "))) (and (not (string= name "")) (setf (nth 1 args) (concat "Term: " name)))) args) (advice-add 'ansi-term :filter-args 'ansi-term--tag-buffer) 

But I recommend you define the advice like this instead:

(defun ansi-term--tag-buffer (program &optional buffer-name) (list program (let ((tag (read-from-minibuffer "Tag: "))) (if (string= tag "") buffer-name (concat "Term: " tag))))) 

This variant actually is self-explanatory.

This seems unfortunate in that, in order to produce a similar effect, it's necessary to copy-paste code: [...] I can copy ansi-term's interactive form

On the contrary, I think it would be a good idea to copy-paste the interactive form of the advised function, even though you don't actually have to do so here.

I read you question from top to bottom. When I got to the code-block I guessed that your advise probably is changing the buffer name. But I didn't know until you later provided the signature as a comment.

In the case under discussion, it appears impossible for the advice author to pass ansi-term only a buffer name, because it's not possible to construct a list which has a value in position 1 but nothing, not even nil, in position 0.

Indeed nothing is less nothing than nothing. :-) But that's hardly relevant here.

As you can see in the documentation you quoted, the value returned by the advice is used as the arguments to the advised function. The return value has to be a list of all arguments not just the ones that have changed.

Staying as close as possible to the old advise, this is what you would have to do using nadvice:

(defun ansi-term--tag-buffer (args) ;; As npostavs pointed out we also have to make sure the list is ;; two elements long. Which makes this approach even more undesirable. (when (= (length args) 1) (setq args (nconc args (list nil)))) (let ((name (read-from-minibuffer "Tag: "))) (and (not (string= name "")) (setf (nth 1 args) (concat "Term: " name)))) args) (advice-add 'ansi-term :filter-args 'ansi-term--tag-buffer) 

But I recommend you define the advice like this instead:

(defun ansi-term--tag-buffer (program &optional buffer-name) (list program (let ((tag (read-from-minibuffer "Tag: "))) (if (string= tag "") buffer-name (concat "Term: " tag))))) 

This variant actually is self-explanatory.

added 230 characters in body
Source Link
tarsius
  • 26.8k
  • 4
  • 76
  • 115

This seems unfortunate in that, in order to produce a similar effect, it's necessary to copy-paste code: [...] I can copy ansi-term's interactive form

On the contrary, I think it would be a good idea to copy-paste the interactive form of the advised function, even though you don't actually have to do so here.

I read you question from top to bottom. When I got to the code-block I guessed that your advise probably is changing the buffer name. But I didn't know until you later provided the signature as a comment.

In the case under discussion, it appears impossible for the advice author to pass ansi-term only a buffer name, because it's not possible to construct a list which has a value in position 1 but nothing, not even nil, in position 0.

Indeed nothing is less nothing than nothing. :-) But that's hardly relevant here.

As you can see in the documentation you quoted, the value returned by the advice is used as the arguments to the advised function. The return value has to be a list of all arguments not just the ones that have changed.

Staying as close as possible to the old advise, this is what you would have to do using nadvice:

(defun ansi-term--tag-buffer (&rest args) ;; As npostavs pointed out we also have to make sure the list is ;; two elements long. Which makes this approach even more undesirable. (when (= (length args) 1) (setq args (nconc args (list nil)))) (let ((name (read-from-minibuffer "Tag: "))) (and (not (string= name "")) (setf (nth 1 args) (concat "Term: " name)))) args) (advice-add 'ansi-term :filter-args 'ansi-term--tag-buffer) 

But I recommend you define the advice like this instead:

(defun ansi-term--tag-buffer (program &optional buffer-name) (list program (let ((tag (read-from-minibuffer "Tag: "))) (if (string= tag "") buffer-name (concat "Term: " tag))))) 

This variant actually is self-explanatory.

This seems unfortunate in that, in order to produce a similar effect, it's necessary to copy-paste code: [...] I can copy ansi-term's interactive form

On the contrary, I think it would be a good idea to copy-paste the interactive form of the advised function, even though you don't actually have to do so here.

I read you question from top to bottom. When I got to the code-block I guessed that your advise probably is changing the buffer name. But I didn't know until you later provided the signature as a comment.

In the case under discussion, it appears impossible for the advice author to pass ansi-term only a buffer name, because it's not possible to construct a list which has a value in position 1 but nothing, not even nil, in position 0.

Indeed nothing is less nothing than nothing. :-) But that's hardly relevant here.

As you can see in the documentation you quoted, the value returned by the advice is used as the arguments to the advised function. The return value has to be a list of all arguments not just the ones that have changed.

Staying as close as possible to the old advise, this is what you would have to do using nadvice:

(defun ansi-term--tag-buffer (&rest args) (let ((name (read-from-minibuffer "Tag: "))) (and (not (string= name "")) (setf (nth 1 args) (concat "Term: " name)))) args) (advice-add 'ansi-term :filter-args 'ansi-term--tag-buffer) 

But I recommend you define the advice like this instead:

(defun ansi-term--tag-buffer (program &optional buffer-name) (list program (let ((tag (read-from-minibuffer "Tag: "))) (if (string= tag "") buffer-name (concat "Term: " tag))))) 

This variant actually is self-explanatory.

This seems unfortunate in that, in order to produce a similar effect, it's necessary to copy-paste code: [...] I can copy ansi-term's interactive form

On the contrary, I think it would be a good idea to copy-paste the interactive form of the advised function, even though you don't actually have to do so here.

I read you question from top to bottom. When I got to the code-block I guessed that your advise probably is changing the buffer name. But I didn't know until you later provided the signature as a comment.

In the case under discussion, it appears impossible for the advice author to pass ansi-term only a buffer name, because it's not possible to construct a list which has a value in position 1 but nothing, not even nil, in position 0.

Indeed nothing is less nothing than nothing. :-) But that's hardly relevant here.

As you can see in the documentation you quoted, the value returned by the advice is used as the arguments to the advised function. The return value has to be a list of all arguments not just the ones that have changed.

Staying as close as possible to the old advise, this is what you would have to do using nadvice:

(defun ansi-term--tag-buffer (&rest args) ;; As npostavs pointed out we also have to make sure the list is ;; two elements long. Which makes this approach even more undesirable. (when (= (length args) 1) (setq args (nconc args (list nil)))) (let ((name (read-from-minibuffer "Tag: "))) (and (not (string= name "")) (setf (nth 1 args) (concat "Term: " name)))) args) (advice-add 'ansi-term :filter-args 'ansi-term--tag-buffer) 

But I recommend you define the advice like this instead:

(defun ansi-term--tag-buffer (program &optional buffer-name) (list program (let ((tag (read-from-minibuffer "Tag: "))) (if (string= tag "") buffer-name (concat "Term: " tag))))) 

This variant actually is self-explanatory.

Source Link
tarsius
  • 26.8k
  • 4
  • 76
  • 115

This seems unfortunate in that, in order to produce a similar effect, it's necessary to copy-paste code: [...] I can copy ansi-term's interactive form

On the contrary, I think it would be a good idea to copy-paste the interactive form of the advised function, even though you don't actually have to do so here.

I read you question from top to bottom. When I got to the code-block I guessed that your advise probably is changing the buffer name. But I didn't know until you later provided the signature as a comment.

In the case under discussion, it appears impossible for the advice author to pass ansi-term only a buffer name, because it's not possible to construct a list which has a value in position 1 but nothing, not even nil, in position 0.

Indeed nothing is less nothing than nothing. :-) But that's hardly relevant here.

As you can see in the documentation you quoted, the value returned by the advice is used as the arguments to the advised function. The return value has to be a list of all arguments not just the ones that have changed.

Staying as close as possible to the old advise, this is what you would have to do using nadvice:

(defun ansi-term--tag-buffer (&rest args) (let ((name (read-from-minibuffer "Tag: "))) (and (not (string= name "")) (setf (nth 1 args) (concat "Term: " name)))) args) (advice-add 'ansi-term :filter-args 'ansi-term--tag-buffer) 

But I recommend you define the advice like this instead:

(defun ansi-term--tag-buffer (program &optional buffer-name) (list program (let ((tag (read-from-minibuffer "Tag: "))) (if (string= tag "") buffer-name (concat "Term: " tag))))) 

This variant actually is self-explanatory.