I notice that the current auto-mode-alist entries all end with a single quote, for example
("\\.java\\'" . java-mode)
What is the purpose of the single quote. I would have expected to see
("\\.java$" . java-mode)
The reason I ask is that I am trying to get files with names matching regexp
^twiki\.corp.*
to open in org-mode. I have tried the following without success:
(add-to-list 'auto-mode-alist '("^twiki\\.corp" . org-mode))
(add-to-list 'auto-mode-alist '("\\'twiki\\.corp" . org-mode))
The following works:
(add-to-list 'auto-mode-alist '("twiki\\.corp" . org-mode))
but is not quite what I want since file names with twiki.corp embedded in them will be opened in org-mode.
\\' matches the empty string at the end of the string/buffer:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Backslash.html e l
$ will match the end of the line: If you have newlines in your filename (very uncommon) $ will match the newline and not the end of the string.
The regex is matched against the whole filename, so you need include "/" to match the directory seperator:
(add-to-list 'auto-mode-alist '("/twiki\\.corp" . org-mode))
Related
I'm trying to associate filenames like "Makefile.OSX" with makefile-mode.
I've tried various combinations such as:
(add-to-list 'auto-mode-alist '("\\^Makefile" . makefile-mode))
(add-to-list 'auto-mode-alist '("\\`Makefile" . makefile-mode))
How do I do this?
The regex specified as part of auto-mode-alist matches against the full pathname, so both of your regular expressions will never match against anything.
You probably want to use something like
(add-to-list 'auto-mode-alist '("Makefile.*\\'" . makefile-mode))
or
(add-to-list 'auto-mode-alist '("/Makefile.*\\'" . makefile-mode))
I am editing some proprietary config files that Emacs autodetects as Conf[JavaProp], i.e. using conf-javaprop-mode from conf-mode.el. That mode is almost perfect, except that these files don't have c or c++ style comments, i.e.
//foo
or
/* foo */
should not be highlighted as comments. Could anyone provide me with some guidance for how I can make my own extensions to conf-mode and automatically load them or whatever from my .emacs ?
You can use conf-mode-initialize to set the comment syntax. For example, here is a simple one for .ctags where # should only start a comment when preceded by spaces. Just modify which conf mode you want to inherit from, and remove the propertize function/syntax table unless you want those modified as well.
(require 'conf-mode)
(defun dotctags-propertize (start end)
(goto-char start)
(funcall
(syntax-propertize-rules
("^\\s-*#.*" (0 "<")))
(point) end))
(defvar dotctags-mode-syntax-table
(let ((st (make-syntax-table conf-windows-mode-syntax-table)))
(modify-syntax-entry ?\; "." st)
(modify-syntax-entry ?\n ">" st)
st))
;;;###autoload
(define-derived-mode dotctags-mode conf-windows-mode "Conf[cTags]"
"Conf Mode for ctags config."
:syntax-table dotctags-mode-syntax-table
(conf-mode-initialize "#")
(setq-local comment-end "")
(setq-local syntax-propertize-function #'dotctags-propertize))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.ctags\\'" . dotctags-mode))
Create your own derived mode from conf-mode and then make it the default mode for your propietary file
(define-derived-mode conf-my-mode conf-unix-mode "Conf[MyMode]"
"Conf mode of my own"
(conf-mode-initialize "#" 'conf-my-mode-font-lock-keywords))
(add-to-list 'auto-mode-alist '("\\.your-extension\\'" . conf-my-mode))
I have added emojis to my org-mode document like this:
bla bla :turtle: bla yadda
When looking at it through the GitHub viewer, they get substituted to the corresponding unicode character entities.
Which hooks I have to pull to get the same effect in org-mode html (esp. ox-reveal) export?
You can use the company-emoji package. Download it and then put the following in your init file:
(require 'company-emoji)
(add-to-list 'company-backends 'company-emoji)
It works for me with org-html-export-to-html. Don't know about ox-reveal though but would assume it will display the emojis as well.
It turns out that there is a customizable variable for this purpose:
org-export-html-protect-char-alist is a variable defined in `org-html.el'.
Its value is (("&" . "&") ("<" . "<") (">" . ">"))
Documentation:
Alist of characters to be converted by `org-html-protect'.
You can customize this variable.
This variable was introduced, or its default value was changed, in
version 24.1 of Emacs.
So for now (not being a hard-core Emacs Lisp user) I just put this in my .emacs:
(defcustom org-export-html-protect-char-alist
'(("&" . "&")
("<" . "<")
(">" . ">")
(":turtle:" . "🐢")
(":dash:" . "💨")
(":-)" . "😊")
(":-(" . "😞"))
"Alist of characters to be converted by `org-html-protect'."
:group 'org-export-html
:version "24.1"
:type '(repeat (cons (string :tag "Character")
(string :tag "HTML equivalent"))))
This works nicely, but maybe there is a better way to just append to the customizable variable?
This question already has an answer here:
Emacs: How to use a major mode for non-standard file extension
(1 answer)
Closed 8 years ago.
I was working with .stp files and .d files, which define kernel probes in c-like syntax. So I would like them to be treated as C source files so I could see the lovely font highlight.
Here are some examples -- just put in whatever mode you need -- e.g., c-mode:
;; associates files with a particular mode.
(add-to-list 'auto-mode-alist '("\\.tex\\'" . lawlist-tex-mode))
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(add-to-list 'auto-mode-alist '("\\.todo\\'" . lawlist-org-mode))
(add-to-list 'auto-mode-alist '("\\.done\\'" . lawlist-org-mode))
(add-to-list 'auto-mode-alist '("\\.scratch\\'" . text-mode))
(add-to-list 'auto-mode-alist '("user_prefs\\'" . text-mode))
(add-to-list 'auto-mode-alist '("\\.lisp\\'" . emacs-lisp-mode))
Does anyone know how I might get emacs to apply the ".ini" syntax highlighting for a ".gcf" file (my own custom file ext)?
I've googled, and my best effort was adding to my ~/.emacs, without joy.
(add-to-list 'auto-mode-alist '("[.]gcf$" . ini-mode))
First find out the mode for ini files. While editing a ".ini" file do C-h m; then add to your ".emacs" the following code:
(setq auto-mode-alist (cons '(".*\.gcf$" . YOUR-MODE) auto-mode-alist))