Syntax highlighting in emacs with perl .t files [duplicate] - perl

This question already has an answer here:
Emacs: How to use a major mode for non-standard file extension
(1 answer)
Closed 9 years ago.
I am using GNU Emacs 24.2.1 to write some perl code. Syntax highlighting works well for files with extension .pl and .pm, but unfortunately not for perl unit tests (.t extension),
Is there a simple way to automatically turn on perl syntax highlighting whenever I open a .t file?

Popular question. I've answered a similar one a few days back: Emacs: How to use a major mode for non-standard file extension.
(add-to-list 'auto-mode-alist '("\\.t\\'" . perl-mode))

Related

How to import/export myst markdown from emacs?

I've been starting to use jupyterbook and it comes with an interesting function called jupytext that can translate md to ipynb and vice versa. Since, I would like to be using emacs for md editing and jupyterbook requires myst flavor: is there a way to tell emacs to export to md using myst flavor? (Well, I'm sure, there is ... the question is rather: has anyone already written an exporter function for that?) Ideally, of course, this could be used, to export ipynb from emacs and import ipynb to emacs org-mode... Am I dreaming too much?

How can I save the state of a Lisp compiler? [duplicate]

This question already has answers here:
Go back to last state
(2 answers)
Closed 8 years ago.
I would like to save the state of a Lisp compiler so that I need not load my file in several minutes, but instead I would load that image in seconds.
Which Common Lisp compiler would do this favor for me?
I came to this idea as Standard ML of New Jersey does this: Exporting Heaps.
I could not find similar in the sbcl manual or the
ecl manual.
With SBCL, use save-lisp-and-die. To restart the image, use the --core arguments.
Read carefully the caveats in the documentation.
With CLISP, use EXT:SAVEINITMEM

emacs (orgmode) does not accept links with non-english characters (osx)

This problem has been partly solved (see below).
I'm using gnu emacs (on OSX) with orgmode and I'm having trouble linking to files with non-english-alphabet characters.
Examples:
this works:
file:~/dor
this doesn't:
file:~/dør
Is it possible to fix this?
PARTIAL SOLUTION:
This problem was partly solved by updating from emacs 23 to 24 (which, at the moment, is "pretest"). (I updated orgmode with package el too but that did not make a difference)
These files now work:
file:~/dør.txt
http://www.dører.no (would open in firefox but with various combinations of symbols for ø)
This still doesn't work:
file:~/dør (file:~/dor works)

Is there a way I could script this scenario with emacs? [duplicate]

This question already has answers here:
Idiomatic batch processing of text in Emacs?
(3 answers)
Closed 8 years ago.
Imagine I have an input file,an output file and a file containing some elisp code, which should transform the input file into the output file. Is there a way I could do all this from an external process? Maybe some kind of script mode for emacs? I would like to embed this in a web application.
See emacs --batch in the Initial Options section of the manual. Use it with -l, 'f' or--eval. Thebatchoption forcesprin1,princ, andprintto print to stdout andmessageanderror` to print to stderr - so you can actually read and write to pipes.
Yes, it is possible. See emacs -l or emacs --eval.

Best way to customize auto-formatting/auto-indenting in vim for Common Lisp

I would like to know the best way to customize auto-formatting/auto-indenting in vim for Common Lisp.
Auto-formatting (I usually do this by typing '==' in command mode per line) works very well for the base lisp language in vim (e.g., defmacro, defun, lambda, if, with-output-to-string), but any time that new language constructs are defined (e.g., using macros), I find that the formatting for the new construct is often not what I'd like it to be.
For example, here's how vim formats 'when (standard lisp construct) and 'awhen (commonly-used anaphoric version of 'when; not part of lisp standard)
(when 'this
(process 'this))
(awhen 'this
(process it))
I would like 'awhen to auto-format like 'when. Any ideas how I can do this?
Edit: Thanks Gilligan and Tamas for the Slimv recommendation. As a test, I downloaded MacVim (will need this working with terminal vim, but that's a different problem) and slimv, rsynched the slimv download into ~/.vim, launched MacVim, and loaded a .lisp file.
I then started up the lisp server (done through a GUI with MacVim), which loaded up my default lisp executable and core file.
And* since my core file is already loaded with the language extensions that I commonly use (awhen being one of them), awhen formatted correctly right out of the box.
I really like this solution. Instead of [1] having to learn how to tell vim to indent particular functions properly, and [2] writing the code that does this explicitly for each language extension that I define, and [3] updating that code every time I add a new language construct. Instead I leverage slimv to do the formatting for me. And slimv can 'learn' new language extensions, as long as those macros are already loaded into the lisp core that the server session is using. Pretty slick!
I have found that this works well for a particular class of language extensions. Usually ones defined as a macro, using the &body keyword. This seems to 'do the right thing' most of the time, but there are macros I use that still don't properly auto-format. Although I'd say that this is more likely to be an issue with how the macro is written (non-standard language extension) than anything else.
So, this solution works well for me for most cases, and I didn't have to code (and maintain) anything. Great stuff!
This might not be a direct answer to your question but I strongly suggest that you install
the slimv plugin: http://www.vim.org/scripts/script.php?script_id=2531
Its a great plugin which integrates SLIME functionality into vim and besides many other things it also comes with an improved indentation for clisp&clojure. It won't indent awhen the way you want though.
For those who are looking for this topic and don't want to run Slimv, because they aren't working with Common Lisp or other reasons, here is the scoop.
Vim's Lisp indentation is not like that for other languages; it has a special "Lisp mode". This mode is turned on by
:set lisp
which is done automatically for .lisp files. Lisp mode isn't a Vim invention; classic Vi implementations have a Lisp mode turned on with :set lisp. (It's not described by POSIX, unfortunately).
Vim's Lisp mode has a simple mechanism for recognizing forms that require operator-style indentation: namely, there is a parameter called lispwords which holds a comma-separated list of identifiers.
You can prove to yourself that this is the identifier list which is used, even when you're editing a Common Lisp .lisp file with syntax highlighting and all. Simply do :set listwords[TAB] and edit the list to remove something from it, such as defun. Then try to reindent a defun: you will see the function-style indentation now instead of the operator-style.
The syntax highlighting support for Common Lisp is separate from Lisp mode's lispwords parameter; it has its own list of identifiers. For example, in Vim 7.3 if you enter this:
(symbol-macrolet ((foo bar))
you get indented out to here!)
This is in spite of the fact that symbol-macrolet is recognized and colored. Why? It's because symbol-macrolet does not appear in the rather scanty lispwords list, whereas it does appear in the lisp.vim syntax highlighting definition file.
The upshot is that you can cob together some script which scans your directory of .lisp files for macros and generates a set lispwords=... command that is placed into a directory .vimrc.
Or if you are working on a custom Lisp dialect, you can just make its Vim syntax highlighting file customize lispwords when it loads.
Here is an implementation oversight: the lispwords option has no local value; you cannot use setlocal lispwords ... to give it a buffer-specific value. In other words, it appears that (at least in the Vim 7.3 I'm using under Ubuntu) you can't have two or more buffers open holding different dialects of Lisp with different identifiers for indentation. The default contents of lispwords contains a smattering of Lisp and Scheme symbols to try to be a kind of "one size almost fits all" solution.
If you filetype is 'lisp' then I think you need to add indenting rules for your special case in the 'lisp.vim' file in the '/vim7x/indent' directory. You can find a bit more info in help at :h indent-expr and :h indentexpr.
Someone may be able to tell you better, but I believe the default lisp.vim indent file basically does nothing because the built-in function lispindent() is used to get indent values. You will want to:
(1) set function used to get indent values (i.e., indentexpr) to a function in your own indent/lisp.vim file, e.g., GetLispIndent().
(2) in your your GetLispIndent() function you will use lispindent() to get indent values to return for all lines except your special case. See other languages' indent files and read the docs to get an idea for how indentexpr works, e.g, java.vim.
#Kaz's answer is completely correct, but they don't go all the way to answering the original question. Vim's lispwords config string is a comma-delimited list of words; when any of the words in lispwords is found at the beginning of an S-expression, Vim will change the way that S-expression is indented. In other words, it defines the "standard lisp constructs" to which the OP refers. If you view your current lispwords config with :set lispwords, you'll see "when" is included, but "awhen" is not, resulting in the following indentation:
(when 'this
(process 'this))
(awhen 'this
(process it))
To fix this, simply add "awhen" to the config string somewhere in your config, like so:
set lispwords+=awhen,
The trailing comma isn't strictly necessary, but the default value includes it, and is probably wise in case you or a plugin modifier elsewhere. That would turn the original formatting into this:
(when 'this
(process 'this))
(awhen 'this
(process it))
(Tested on my current installation of Vim 9.0)
Note that, as #Kaz points out, this config string is universal, so if you have different dialects of lisp their indentation will all be controlled by this setting. Vim is pretty good about auto-detecting lisps, but you may need so :set lisp if it doesn't recognize your filetype or dialect.