2

I use TAB to expand snippets from yasnippet, when it doesn't expand a snippet, it usually falls back to indenting (the default command bound to TAB), this is referred to by yasnippets custom variable yas-fallback-behavior which can only be call-other-command or return-nil.

The desired functionality I want is upon hitting TAB:

  1. Tries to complete snippet, succeeds, or fails silently.
  2. Checks if we're in PHP mode, and calls php-complete-function, succeeds, or fails silently.
  3. Defaults to it's current indentation command (indent-for-tab-command).

It currently performs 1, then 3, perfectly. I was however, able to make it work for the most part by advising yas--fallback with this bit of code:

(defadvice yas--fallback (before try-php-expand (&optional arg from-trigger-key-p) activate)
  (when (string-equal mode-name "PHP")
    (php-complete-function)))

The only main issue that remains is that when trying to indent anything using TAB, php-complete-function does not fail silently, but instead spams the minibuffer with messages from it's multiple checks for a PHP completion.

So is there a way to disallow messaging from that function in this case, without doing all the same checks it does essentially re-programming the function in my advise? Alternatively, is there a better way to do this with yasnippet to begin with that I'm missing?

Drew
  • 29,895
  • 7
  • 74
  • 104
Dan LaManna
  • 3,431
  • 4
  • 23
  • 35
  • So this isn't really about `yas` but about `php-complete-function` right? – pmr Nov 27 '12 at 21:35
  • Not really, you could substitute `php-complete-function` with anything a user would want to do after a failed snippet completion. See the very last sentence of the question. – Dan LaManna Nov 27 '12 at 21:38
  • `(let (message-log-max) (message "foobar"))` seems to be the way to disable logging according to the manual, but it doesn't work for me on Emacs 24 or I misunderstand the purpose of this. – pmr Nov 27 '12 at 22:19
  • *facepalm* I was looking at the log of the thing that was returned. – pmr Nov 27 '12 at 22:59
  • 1
    @DanLaManna: Side remark, replace `(string-equal mode-name "PHP")` with `(derived-mode-p php-mode)`. – Stefan Nov 28 '12 at 02:01

2 Answers2

0

You can turn of logging in any expression by setting message-log-max to nil.

(defadvice yas--fallback (before try-php-expand (&optional arg from-trigger-key-p) activate)
  (when (string-equal mode-name "PHP")
    (let (message-log-max)
      (php-complete-function))))
pmr
  • 58,701
  • 10
  • 113
  • 156
  • This does stop it from logging to *Messages* but continues to display messages in the minibuffer, which is the main issue. I'm afraid I may need to adjust my advice to check all the checks `php-complete-function` does. – Dan LaManna Nov 28 '12 at 00:41
  • @DanLaManna You can minimize output to the echo area by setting `message-truncate-lines`. Please post a full solution if you have found it. :) – pmr Nov 28 '12 at 11:09
0

You could try something like (guaranteed 100% untested):

(defvar my-inhibit-messages nil)
(defadvice message (around my-inhibit activate)
  (unless my-inhibit-messages ad-do-it))

(defadvice php-complete-function (around my-silence-php-messages activate)
  (let ((my-inhibit-messages t))
    ad-do-it))
Stefan
  • 27,908
  • 4
  • 53
  • 82