Deactivate specific yasnippets in Emacs - emacs

With Yasnippet recently updated from MELPA, I would like to be able to deactivate only the snippets xxx and todo that come with text-mode. The first expands with x and the other with t, which bother me because I write math texts in org-mode and I need to write several x's and t's by themselves, and then press TAB to exit parenthesis.
From yas-buffer-local-condition, it seems that I might be able to do something if there was a #condition: directive in the snippets, but the mentioned snippets don't have one.
I get my way if I just delete the files, but unfortunately they reappear at each update of Yasnippet.

One possible solution would be to control the snippets with key bindings by adding a line of code to each snippet -- e.g., # binding: C-I a b c or # binding: C-I d e f  The combination C-I is equivalent to the tab key and the space between the following letters means that they are pressed individually one at a time. In addition, the following lines of code can also be modified to reflect different key(s): # key: a_b_c and # key: d_e_f.
The variable yas-snippet-dirs can be used to control the location(s) of snippets. It may be a good idea to move snippets to a different location so that they are not touched by future updates (e.g., el-get).
The xxx snippet looks like this:
ORIGINAL
# -*- mode: snippet -*-
# name: xxx
# key: x
# --
`(yas-with-comment "XXX: ")`
MODIFIED
# -*- mode: snippet -*-
# name: xxx
# key: a_b_c
# binding: C-I a b c
# --
`(yas-with-comment "XXX: ")`
The todo snippet looks like this:
ORIGINAL
# -*- mode: snippet -*-
# name: todo
# key: t
# --
`(yas-with-comment "TODO: ")`
MODIFIED
# -*- mode: snippet -*-
# name: todo
# key: d_e_f
# binding: C-I d e f
# --
`(yas-with-comment "TODO: ")`
For those who are curious, the function yas-with-comment looks like this
(defun yas-with-comment (str)
(format "%s%s%s" comment-start str comment-end))

Related

How to expand the key before which there is a non-key string?

For example, this is my snippet in python mode:
# -*- mode: snippet -*-
# name: (
# key: (
# --
($0)
I can expand (to (), but I can not expand a( to a().
How to expand a( to a()?
Although I don't use them, there are minor modes like smartparens mode (https://github.com/Fuco1/smartparens) which automatically inserts or deletes the matching brackets which will probably work a lot better than using snippet.

can #+BIND: be wrapped?

Correct Version:
#+BIND: org-html-postamble-format (("en" "abcxyz"))
but if the format string is very long, is there a way to wrap it to multilines?
something like this:
#+BIND: org-html-postamble-format (("en" "abc ~
# xyz"))
Unfortunately no. Keywords in org-mode are constrained to a single line and there is no wrapping character. If you feel strongly about your line length you might consider:
Using the #+SETUPFILE mechanism (see: In-buffer settings)
Defining that format in your dotemacs file so you can span multiple lines.
Using some form of local file or directory variables. For example local variables may span multiple lines:
# Local Variables:
# eval: (setq org-html-postamble t)
# eval: (setq org-html-postamble-format '(("en" "foo
# bar \
# baz")))
# End:
Note: You may notice that some some particular keywords have "wrapping" behavior such as node properties (http://orgmode.org/manual/Property-syntax.html):
#+PROPERTY: var foo=1
#+PROPERTY: var+ bar=2
Behavior like this is special and limited to those keywords. No equivalent wrapping behavior exists for the BIND keyword.
Current org-mode version (as of this post): 8.3.4

How to remove indentation for a line in yasnippet for python-mode?

I would like to close my if statements with a comment indicating the condition checked in the if statement. I am using yasnippet with emacs and the snippet I use is this:
# -*- mode: snippet -*-
# name: if
# key: if
# group : control structure
# --
if ${1:cond}:
$0
# endif $1
My problem is that the final # endif comment gets aligned with $0. Is there a way to make it align with the if statement?
The value of yas-indent-line controls this behavior. Try adding
# expand-env: ((yas-indent-line 'fixed))
to the header.

Individual code formatting for files in Emacs

Is there equivalent plugin like modeline_magic from VIM?
So each file could look like e.g.:
/* vim: set tabstop=8:softtabstop=8:shiftwidth=8:noexpandtab */
int main(int, char *) {}
and indentation would be passed to other clients?
You can add local (file) variables by having a line formatted as
-*- mode: modename; var: value; ... -*-
at the start of your file. Any number of var: value; pairs can appear in the line. If you're finding that you have too many local variables, you can change the style to
# Local Variables:
# mode: python
# comment-column: 0
# End:
Emacs searches for the string "Local Variables", and is smart enough to work out that the prefix and suffix (in this case # and nothing) should be reused for the following lines. This means that if the file is something other than python, you can change the prefix/suffix to match the different comment characters, e.g. /* and */ for ANSI C.
You can read more at the emacs manual.

How to import/expand noweb refs in evaluated (exported) source blocks in org-babel?

I'm trying to do something like this:
* Define some functions
#+begin_src python :noweb_ref defs
def f1(a,b,c):
return True
def f2(d,e,f):
return False
#+end_src
* Use them in a results-exported block later
#+begin_src python :results output :exports both :tangle yes
<<defs>>
print "test results:"
print f1(1,2,3)
#end_src
What I want to happen is for <<defs>> to be expanded tangle-style when the block is evaluated to produce the export output. What actually happens is that <<defs>> gets evaluated literally and causes a syntax error.
When tangling blocks like this to an output file, everything works perfectly, but I can't figure out how to do the same thing when I'm exporting the buffer.
Suggestions?
I'm not sure to really understand your point... but
1) you miss a noweb:yes header argument
2) you can use <<func()>> to insert the results of evaluating func (instead of the code of func) -- that's here that I'm not sure about what you really want.
You can also use :noweb no-export. That shows the noweb-syntax in exported files but expands the code blocks when evaluating or tangling the files.
:noweb strip-export is great if you just want to show an algorithm:
<<prep>>
result = A + B
<<plot>>
The exported file then shows this:
result = A + B