Haven't found a way to indent/autoformat HOCON config files. What is you way here?
I'm fairly certain there isn't an Emacs major mode for HOCON. But it looks like it's similar to JavaScript, so you can make .hocon load as JavaScript by adding this to your .emacs:
(add-to-list 'auto-mode-alist '("\\.hocon\\'" . javascript-mode))
I think it's quite similar to the syntax of HCL. You might be interested in using emacs-hcl-mode for editing HOCON files.
Related
There are multiple questions along these lines but I haven't been able to find what I need from start to finish. I have been using emacs for a few years but am not used to its customization.
I have a unique file type, identified by its extension, which emacs is not configured for. Its comment style is
<!-- text -->
and I would like to set the variables comment-start and comment-end to the relevant values (which I am assuming will allow me to use comment-region). I don't know the correct way to do this so that it will always be configured when I open this file type but won't affect the default behavior of emacs.
Do I need to make a new major mode for this file type, and then set the variables, or is there an easier way of doing it? An example of the complete requirements for my .emacs file would be much appreciated!
See here. I think this will work:
(add-to-list 'auto-mode-alist
'("\\.extension\\'" . (lambda ()
(setq-local comment-start "<!--")
(setq-local comment-end "-->"))))
Alternatively, if this file extension is well known (or if these files are close enough to a well known syntax), you may be able to just find a major-mode online that does what you want. For example, NXML Mode may just give you the comment syntax you want along with some other useful features.
I am trying to get into emacs. I have installed it using apt-get install on ubuntu.
Now I want to change the background color, and found some doc on this. The best doc I found is this:
http://www.emacswiki.org/emacs/FrameParameters
But when reading about how to add things to the .emacs file, none of the docs/info I found mention anything about structure, and the .emacs file just looks like a big mess. Do any of you experienced emacs users follow a specific structure when adding to .emacs, or do you just add anywhere?
I want to add the following:
(add-to-list 'default-frame-alist '(foreground-color . "white"))
(add-to-list 'default-frame-alist '(background-color . "black"))
(add-to-list 'default-frame-alist '(cursor-color . "coral"))
When opening the .emacs file, I don't file like just throwing it in, as I like structure. Before I try to make my own, I'd like to hear if there is a convention that I have missed?
Your .emacs file is a piece of Lisp code. There are conventions for how to format Lisp code, but I guess that's not really what you are looking for.
Part of the problem is that your .emacs will tend to grow organically, as you find new things you want to try and new knobs you want to tweak. Over time, it will build up into a huge, monolithic piece of unrelated code snippets.
The usual structuring conventions for code apply -- group related code together, add comments, modularize.
What you can do with the code you posted as an example is mainly to add a comment.
;; Frame colors
(add-to-list 'default-frame-alist '(foreground-color . "white"))
(add-to-list 'default-frame-alist '(background-color . "black"))
(add-to-list 'default-frame-alist '(cursor-color . "coral"))
Some people like to add folding mode markers so they can collapse/expand code sections, but perhaps at that point you should start thinking about breaking it up into smaller files.
Overhauling the rest of your .emacs file is out of scope here, and impossible without access to the full thing. But see http://www.emacswiki.org/emacs/DotEmacsModular for some suggestions. (Disclosure: A snippet of mine is prominently linked.)
Using customize also helps somewhat, but it has its own pros and cons. The customize settings are added programmatically at the end of your .emacs, and has very little by way of structure.
I use web-mode in Emacs, everything is fine except that when editing a .js.erb file in Rails.
Because there's only 2 modes in .js.erb file: js and ruby and web-mode only recognize javascipt code in <scipt type="javascript"></scipt>.
I'm not very familiar with emacs and web-mode, maybe there's a way to config.
You can change the "default" mode of an active buffer by modifying the variable web-mode-content-type, e.g. from M-::
(setq web-mode-content-type "javascript")
Default modes may be specified by file name (or pattern) by modifying the web-mode-content-types alist somewhere in your configuration, e.g.
(eval-after-load "web-mode"
'(add-to-list 'web-mode-content-types '("javascript" . "\\.js\\.erb\\'")))
The web-mode's author already fixed this, so just update your web-mode
I have the very same problem detailed here caused by the '$'-included in the \Sexpr command-breaking the syntax highlighting of Emacs. Unfortunately no definitive solution has been proposed yet.
Now I read a solution for a similar problem here that I am trying to adapt to my situation. The idea is to set \Sexpr as verbatim environment in Emacs' preferences.
I tried
(setq LaTeX-verbatim-environments-local '("Sexpr"))
but with no result.
Using
(add-to-list 'LaTeX-verbatim-macros-with-braces "Sexpr")
and restarting LaTeX-mode worked for me.
after setting a path for my lisp files in emacs in the .emacs file, like this
(add-to-list 'load-path "~/elisp/")
logically I should also use a load command for a specific file I guess what is that command
I tried
(load-file-name "google-c-style") with the .el added also for the file, what should be the right way to do this
however no success.
It's just (load), not (load-file-name).
If the .el has a line like (provide 'google-c-style), then all you need in your .emacs is:
(require 'google-c-style)
load-file-name is a variable which holds the full name of the file loaded by 'load'
use C-h-v load-file-name to read the documentation
Now, to load a file use the function 'load' - This looks for elisp source or binaries in the loaded paths
Eg: (load "google-c-style.el")
Note: There are another functions 'load-file'and 'load-library which work slightly differently. Read more about these here: http://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html#Lisp-Libraries
Also, as mentioned in one of the answers one can also use the provide - require feature.
Read this post to learn more about the differences between these functions(load, load-file, require, autoload)
http://ergoemacs.org/emacs/elisp_library_system.html