Is it possible to highlight interpolated perl variables in emacs? - perl

Recently I've started using emacs and after overcoming a number of hurdles in making cperl-mode operate in a way that is agreeable I've become stumped by this problem. Currently I have all scalars in regular use being highlighted except for where they are interpolated. Is such syntax highlighting possible under this mode? Currently I'm using emacs 23.1 and jrockway's cperl-mode 5.23
Thanks

It won't highlight interpolated variables in strings, but it will do it in regular expressions. I'll bet that could be adapted by somebody who knows elisp.

Related

How to highlight my own syntax in Emacs?

I am developing my own Domain Specific Language (DSL) and the filename extension is .xyz.
Emacs doesn't know how to highlight syntax in .xyz files so I uausally turn on typescript-mode or json-mode. But the available syntax highlight mode is not good enough for me, so I am considering writing my own syntax highligher for Emacs editor. Any tips on this task? Any toolkit recommendation?
Alternatively, I would be happy with any available mode that highlights common keywords such as class, string, list, variables before =sign and after # sign, braces {}, brackets [], question mark ? and exclamation mark !. Any existing languages have similar syntax?
I am not color-blind and not picky on colors. Any syntax highligher that highlights above syntax can solve my problem.
If you are satisfied with simple syntax highlighting for keywords and comments only, there is a helper for this called define-generic-mode, which is documented in the elisp manual.
Some examples of using it can be found in generic-x.el distributed with Emacs.
But highlighting of variable names is not covered by this. For that, you need to be able to parse the DSL using semantic/bovine, as whether a particular string is interpreted as a variable name depends on context, and not just simple regexp matching.

perl-style regular expressions in emacs

Is there a way to use perl-style regular expressions in Emacs? I use regexp-builder and query-replace-regexp pretty often but the Emacs-style regexes throw me off sometimes.
After a bit more searching I found a few similar questions:
Is it possible to change emacs' regexp syntax?
Elisp mechanism for converting PCRE regexps to emacs regexps
It looks like the solutions is to write an elisp function to convert PCRE's to Emacs-style regexes. This code on GitHub looks like a pretty good option.

Getting Emacs to recognise custom math delimiters so it can colour the face accordingly

I have found a code to make typing equations in LaTeX in a simpler and faster way. Instead of typing
\begin{equation}
\end{equation}
I can now type
\be
\ee
It works great and I am happy with it. The code, found in this document (p. 13), is
\makeatletter
\newcommand{\be}{\begingroup
\setlength{\arraycolsep}{2pt}
\eqnarray%
\#ifstar{\nonumber}{}%
}
\newcommand{\ee}{\endeqnarray\endgroup}
\makeatother
My problem is that I use emacs, and it doesn't recognise those math delimiters and hence it doesn't give the face the proper math colour. I have tried to customise this by using the command M-x customize-apropos to try and find something I could use, but the closest I got were the variables
'font-latex-math-environments',
which I don't think is what I am
after since from what I can see I
can only type the name of the
command which goes inside the curly
brackets in \begin{} and \end{}
'font-latex-make-built-in-keywords',
which would require more knowledge
from me than I have, and I don't
even know whether it would work.
What I would like to know, thus, is how to set up Emacs so that whenever I used the pair \be and \ee it would give the face the same colour as I set up for math. I imagine this would require an emacs lisp code, which would be great so I could modify it to include other things if so I wished.
Can anyone help me getting this done?
This is not really an answer to your question, but if it's just about saving keystrokes for writing an equation environment, you might want to try the following.
From the tags under your question, I assume you're using AUCTeX mode. With that, instead of typing
\begin{equation}
\end{equation}
every time, use the following shortcut to have AUCTeX insert an environment interactively: C-c C-e. This will prompt your for the name of the environment ("equation") which you can type using tab-completion.
So you do save a couple of keystrokes, the result is syntactically correct, you don't need the additional \be and \ee commands, and what's best is that this approach is generic, i.e., it works for all LaTeX environments, not just equation.

ispell in Emacs LaTeX mode

When I run Emacs command ispell-buffer on an Emacs buffer which is in the LaTeX mode, ispell checks spelling also inside math expressions.
I'd very much like to disable this. Is there an easy way to do it?
I've read about detex but detex does not seem to be integrated into Emacs.
It shouldn't do this, if you are using latexisms (eg. \[ ... \], equation environments, &c) to invoke math mode. Check the contents of ispell-tex-skip-alists; cf. section 6 of the ispell FAQ for what kind of thing should be there.
You can use $..$, $$..$$ to mark out maths using ispell-tex-skip-alists, but beware getting them out of kilter...
Postscript
Check also the value of the ispell-parser variable: this should be 'tex, otherwise ispell will not look for $...$ and $$...$$ regions.
Yes, you can: install aspell instead of ispell, and use flyspell with it.
This doesn't answer your question directly, but I have found Flyspell, an on-the-fly spell checker, incredibly useful when editing LaTeX documents. It still spellchecks inside equations, but it is much easier to ignore a few extra red underlines than ispell's interactive commands.
You may know this, but you can press A during spell checking to add a word to the buffer-local dictionary (that's capital A, lowercase a adds it to the global dictionary). It's not ideal, but this is how I usually suppress spell-checking of technical terms and variable names, etc., in my LaTeX documents.
This AUCTeX mailing list thread : "spell checker (ispell-buffer) complains about products in math modes" has some workarounds and the answer demonstrates how to use ispell-tex-skip-alists.
Another approach is to use ispell-skip-region-alist. The following example is to exclude org-mode src blocks:
(add-to-list 'ispell-skip-region-alist '("#\\+begin_src". "#\\+end_src"))

Can emacs longlines-mode or visual-line-mode be made to respect indentation and lists?

I use emacs to edit most of my answers for SO, and although I use longlines-mode (I have not upgraded to emacs 23 because of some critical bugs that don't look like being fixed any time soon), I can't find a way to get longlines-mode to respect the indentation used for Markdown. I would really like to fix this, but I want it for an ordinary buffer, not for org-mode (as already answered).
Does anybody have suggestions on how I can get longlines-mode to indent wrapped lines? I am definitely willing to try hacking the Emacs Lisp, although my Emacs Lisp is pretty rusty...
I just looked through the source code of longlines.el. There doesn't seem to be any hook there to have the wrapped lines indented. If you want to do this, you'll need to write a bit of elisp (and, more importantly, understand all of the functions for doing text-properties.)