emacs: find-file-at-point -- how to escape spaces in filepath? - emacs

I am new to emacs... when using ffap to open the file under cursor, I noticed that ffap does not recognize spaces in the file path. Tried to escape the space (just like in vim), but it seems not work.
I hate spaces in filename as well, but we just don't have control sometimes. Wonder if there any nice emacsian way of handling such cases?
Did some search and found that the cygwin emacs has a patch to deal with spaces in the path, yet it is not available to the linux emacs.

Related

Disable automatic LaTeX symbol replacement in VS Code

When editing RMarkdown files in Visual Studio Code, the editor automatically replaces many LaTeX-style sequences with their unicode 'equivalents'. E.g., when I type \sum followed by a space, it is converted to ∑. While this is convenient in some cases, it is catastrophic when trying to embed LaTeX source into my file for rendering later on. Typing something like $\sum \sqrt {x_i}$ is converted to $∑ √ {x_i}$, which renders quite differently. Even pressing "escape" when the suggested replacements show up does not prevent the substitution.
Is there a way to turn this off? I've looked through the settings quite thoroughly and cannot find a way to do so. Any help would be appreciated!
(The workaround I've come up with is to copy a single space character and paste it after my symbol instead of pressing the space key on the keyboard.)
Visual Studio Code Version: 1.63.2
Mac OS 10.14.6
It turns out I had an extension installed called "Fast Unicode Math Characters" which, true to it's name, was inserting unicode math characters 😅
Disabling this fixed the issue.
(I decided to answer my own question rather than deleting the question in case someone else has a similar issue)

How to hard-wrap lines in VS Code at a specific character (NOT word wrap)

I have a Base64 encoded string in a text file that is one line. In other words it contains no line breaks. I want to insert a line break every 78 characters.
None of the "wrap" extensions I have found do this, since they're geared for word wrapping and use word boundaries. Running any of these functions does nothing since the string contains no spaces or word boundaries.
I can do it on Unix using something like fold -w 78 but this seems like something that should exist in VS Code or at least an extension.
I'm not aware of an extension that does specifically what you're asking for, but what I would do is use the Edit with Shell Command extension, and use it to run fold -w 78 on the text in question from within VSCode. The extension even has a "quick command" feature you can use to save that command for quick use if it is something you do often.
I use that extension fairly often for one-off transformations with things like sort, sed, tr, and fmt. It's really handy when you know how to express the desired transformation as a shell command.

Using emacs in batch mode to dump a file with syntax highlighting?

I'd like to use emacs in some kind of batch mode to just render a file with syntax highlighting and exit. Specifically, I want to dump the fontified buffer with ANSI escape codes so that it shows up reasonably syntax-highlighted on my terminal. Is there any way to do this?
The ansi-lpr.el library seems to be kind of along the lines of what I want, but the output isn't colorified. I can't figure out how to get over that final hurdle — there are a lot of modules to digest ANSI escape codes into Emacs text properties (e.g. ansi-color.el) but I haven't found anything that does the reverse. If anyone can point me to something that does, I think I can piece together the rest.
Alternatively, I've seen some hacky approaches like this answer (using script and capturing the output) but in my experiments that approach has seemed unlikely to be fruitful — you get tons of undesirable control sequences mixed in with the highlighted text.
The overarching motivation here is to use emacs in a $LESSOPEN pipe to get syntax highlighting when I page files. In case you're going to say it, I've tried and "just page files in Emacs" is not acceptable for me.
I'm glad to announce a new package, e2ansi, that (hopefully) does what you asked for.
The package provides a command-line tool e2ansi-cat that starts Emacs in batch mode, opens files, syntax highlight them (using font-lock), and creates ANSI-colored versions of the syntax highlighted files.
You can integrate this into less by setting the following variables to, for example:
export "LESSOPEN=|emacs --batch -Q -l ~/.emacs -l bin/e2ansi-cat %s"
export "LESS=-R"
export MORE=$LESS
The end result looks like the following:
You can vary the colors and attributes like bold, underline, and
italics by using a suitable Emacs theme.
The e2ansi package is located at https://github.com/Lindydancer/e2ansi
Personal note
I would like to thank you for posting this question, it directly inspired me to write e2ansi.

What to use (instead of C-x C-f) to open a UTF-8-encoded file?

I know that including a directive like -*- coding: utf-8 -*- near the top of a file tells Emacs to assume a UTF-8 encoding, but more often than not, I want to open UTF-8-encoded files that do not include such a directive. (In some cases, modifying the file to add the coding directive would not be a big deal, but even then this is a very unsatisfactory solution.)
In such situations, what should I use (instead of plain C-x C-f) to open a file using UTF-8 as coding system?
EDIT: to be clear: even "modern Emacs" sometimes guesses the wrong coding system (possibly due to an error or corruption in the file); I want to tell Emacs: when opening this file, ignore your heuristics, assume a UTF-8 coding. Basically, I want the equivalent of a -*- coding: utf-8 -*- directive that does not require me to modify the file.
Try prefixing your command with C-xRETc to manually specify the coding system. For example:
C-xRETcutf-8RET (tell emacs that the following command should use utf-8)
C-xC-fpath/to/your/fileRET (open the file)
But as noted in the comments, this should normally not be necessary if your system is well configured.
As already said, with modern Emacs you should not have to do anything for opening correctly an utf-8 encoded file.
That said look for set-language-environment in your .emacs, You could try to remove it, or to write:
(set-language-environment "utf-8")
For configuring Emacs to use utf-8 as default encoding.

How to ignore comments in the LaTeX file with ispell (within Emacs if possible)

I'm writing a text with Latex in English but written my comments in Finnish. When I'm running the spell checking with ispell, I got to run through all the comments. Is there a handy way to skip the comments with the ispell? If that could be done with emacs, that would be double handy =)
One way would be to run the ispell within console and process the input with sed, for example, but I'd like to have my changes straight on the file...
(setq ispell-check-comments nil)
You'd have to dig in the code a bit, but when you spell-check a file, it's running the detex tool to strip out the TeX code. You should be able to modify the pipeline to have a sed or perl script strip the comment lines.
I kind of vaguely think AuC-TeX makes this configurable, but 30 seconds looking didn't reveal it.
Adding a modern answer to this old question, because I also had the problem:
Just use aspell, which does this out of the box.