I'm trying to set up an emacs environment like this guy, but I keep getting this darn error:
Syntax read error: )
Here's what my init.el file looks like, it's not long, but I have NO idea what any of it means. I'm brand spankin new to lisp.
(add-to-list 'load-path' "~/.emacs.d/auto-complete-1.3.1")
;Load the default configuration
(require 'auto-complete-config')
;Make sure we can find the dictionaries
(add-to-list 'ac-dictionary-directories' "~/.emacs.d/auto-complete-1.3.1/dict")
;Use dictionaries by default
(setq-default ac-sources (add-to-list 'ac-sources' 'ac-source-dictionary'))
(global-auto-complete-mode t)
;Start auto completion after two characters of a word
(setq ac-auto-start 2)
; case sensitivity is important when finding matches
(setq ac-ignore-case nil)
(add-hook 'js-mode-hook'
(lambda ()
;;Scan the file for nested code blocks
(imenu-add-menubar-index)
;;Activate folding mode
(hs-minor-mode t))
You have unbalanced parentheses in the call to add-hook at the end.
Basically, add an extra ) to the two at the end.
If you type M-x show-paren-mode RET and then position the cursor after a closing parenthesis, it'll highlight the matching opening parenthesis (and vice-versa if you position the cursor on an opening paren).
You have extra quotes at the end of some symbols. In lisp, you quote an expression by putting a single quote (') immediately before it and nowhere else: 'correct, 'incorrect'. String literals are like many other languages, with double quotes both before and after: "a string literal".
Also, the missing paren as pointed out by phils.
In general, you can start emacs with --debug-init to make it do a backtrace on any errors in your init file. In this case it's not very useful because the code isn't even evaluated.
Related
I am trying to run emacs with proof generale to open Coq files. However, when I open emacs I get the following error message:
Symbol's value as variable is void: “/Users/myusername/.opam/default/bin/coqtop”
My emacs file is as follows:
(setq coq-prog-name “/Users/username/.opam/default/bin/coqtop”)
(require 'package) ;; (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3") ; see remark below (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize)
(custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(package-selected-packages '(proof-general))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. )
Any advice on how to make my emacs work with coqtop?
Emacs treats “/Users/myusername/.opam/default/bin/coqtop” as a symbol because it's a sequence of ordinary characters. It does not start with an (ASCII) double quote, it starts with the character “ and ends with the character ”. They non-ASCII left and right double quotes. Use the ASCII quote ", which is the string delimiter in Emacs Lisp (and many other programming languages).
(setq coq-prog-name "/Users/username/.opam/default/bin/coqtop")
Don't edit source code with word processors that insert “smart quotes” and other features meant for text read by humans. The best place to edit your Emacs configuration is Emacs itself. Emacs knows what type of file you're editing and won't do such substitutions in programming modes (unless you've gone out of your way to configure it to do so, in which case, don't).
I have the following code that attempts to create a new line and then jump to it. The idea is that move-end-of-line will jump to the end of the current line, and ["C-m"] would act as return/enter. Yet executing this command gives the error: "wrong number of arguments". How do I fix this?
(global-set-key (kbd "C-.") 'new-line)
(defun new-line ()
(interactive)
(move-end-of-line)
["C-m"]
)
I think you need to read the Emacs & elisp manuals: these questions are pretty easy to answer. Here's one way to do it.
(defun insert-line-after-line (&optional n)
(interactive "p")
(end-of-line 1) ;end of current line
(open-line n) ;open n new lines
(forward-line 1)) ;go to start of first of them
But seriously: Emacs has very extensive self-documentation, it is easy to find out how to do these things.
An option is to record a macro and use that.
M-x kmacro-start-macro
C-e
C-m
M-x kmacro-end-macro
If you don't care about the macro persisting, just run it:
C-x e
But if you want it to persist you would save it:
M-x name-last-kbd-macro new-line
M-x insert-kbd-macro new-line
and paste the output into your initialisation file (with your shortcut definition):
(global-set-key (kbd "C-.") 'new-line)
(fset 'new-line
[end return])
["C-m"] is like the way you specify a key for doing a key binding, but this is not the same as how you programmatically tell Emacs to insert a character into a document. You could use (insert-char ?\^M) (see ref here), but that would result in a literal ^M character (try it; another way to do the same thing interactively is Ctrl-Q followed by Ctrl-M). (insert "\n") seems to be what you're looking for.
Also, the reason you're getting the message "wrong number of arguments" is because (move-end-of-line) requires an argument when called out of interactive context. (move-end-of-line 1) works.
That said, possibly an easier way to achieve the result you're looking for is with the following setting:
(setq next-line-add-newlines t)
This will allow you to just do C-n at the end of the file and not worry about the distinction between moving and inserting.
{It has been asked before: Emacs: highlight matching paren when cursor is on it, not after it but none of the answers are satisfactory}
I am using mic-paren with following .emacs settings (although the problem exists with all similar emacs packages, so it seems to be some kind of default emacs behavior)
(paren-activate)
(setq paren-match-face 'highlight)
(setq paren-sexp-mode t)
which highlight the all the text between two parenthesis. It works well when the cursor is ON opening parenthesis but from the other side, I have to put my cursor AFTER the closing parenthesis. This results in strange behavior when used with slime (which requires the cursor to be put ON the closing parenthesis to display general usage information and such). Is there any way to change this behavior and make emacs match parenthesis when the cursor is ON closing parenthesis?
EDIT: Minor grammar fix
Don't know about mic-paren, but using the built-in show-paren-mode, you can get what you want in Emacs-24.4 with:
(defun my-show-paren-any (orig-fun)
(or (funcall orig-fun)
(if (looking-at "\\s)")
(save-excursion (forward-char 1) (funcall orig-fun)))))
(add-function :around show-paren-data-function #'my-show-paren-any)
The following works for `mic-paren'. But, it has some afterglow;-). The opening delimiter is highlighted if the cursor is on the closing delimiter or just behind it.
(defadvice mic-paren-highlight (around cursorOnClosing activate)
"Dirty hack to highlight sexps with closing delim below cursor"
(if (eq (char-syntax (following-char)) ?\) )
(let ((paren-priority 'close))
(save-excursion
(forward-char)
ad-do-it))
ad-do-it))
Naturally, to make this work you need to install mic-paren correctly. Just follow the installation guide in mic-paren.el cited here:
Installation:
Place this file in a directory in your 'load-path and byte-compile
it. You can surely ignore the warnings.
Put the following in your .emacs file:
(GNU Emacs supports mic-paren only within a window-system but XEmacs
supports mic-paren also without X)
(when (or (featurep 'xemacs) window-system)
(require 'mic-paren) ; loading
(paren-activate) ; activating
; set here any of the customizable variables of mic-paren:
; ...
)
Restart your Emacs. mic-paren is now installed and activated!
To list the possible customizations enter C-h f paren-activate' or
go to the customization groupmic-paren-matching'.
EDITS:
follow Stefan's hint about (featurep 'xemacs)
What's important to remember here is that Emacs's point is between two characters, not on a character. For the show-paren facility to trigger, the point must be immediately outside a paren, whether opening or closing. The observed dissymmetry is caused by the block cursor being placed, arbitrarily, on the character after (rather than before) the point.
If this disturbs you, then a workaround would be to use a line cursor rather than a block cursor.
show-paren-mode is being enhanced for the next but one release, such that it will trigger also with the point immediately inside a paren.
The following advice does what you want. When the block cursor is "on" the opening parenthesis, the closing parenthesis is highlighted. When the block cursor is "on" the closing parenthesis, the opening parenthesis is highlighted.
(advice-add show-paren-data-function
:around
(lambda (orig-fun)
(cond ((looking-at "\\s(")
(funcall orig-fun))
((looking-at "\\s)")
(save-excursion (forward-char 1) (funcall orig-fun))))))
Refer to my answer on the Emacs Stack Exchange site: https://emacs.stackexchange.com/a/63458/17507. In that answer, I provide a full explanation of the code above, and also a suggested variant.
I'd like to highlight a new command I created in LaTeX:
\newcommand{\conceito}[3]{
\subsection{#1} (Original: \textit{#2} #3).
}
I use this code in this way:
\conceito{Foo}{Bar}{Bla}
I followed the manual and put this code in my ~/.emacs, but it didn't work:
(add-hook 'LaTeX-mode-hook
(lambda ()
(font-lock-add-keywords nil
'((""\\<\\(\\conceito)\\>"" 1 font-lock-warning-face t)))))
What's wrong?
EDIT: Deokhwan Kim originally pointed out that your regexp contains two consecutive double quotes, and that the closing parenthesis ) needs to be escaped with double quotes as well:
(add-hook 'LaTeX-mode-hook
(lambda ()
(font-lock-add-keywords nil
'(("\\<\\(\\conceito\\)\\>" 1 font-lock-warning-face t)))))
In addition to the points pointed out by Deokhwan Kim, there are also the following two issues:
You need four backslashs instead of two in front of 'conceito': \\\\conceito
The backslash sequence \\< matches the empty string only at the beginning of a word, however, the backslash at the beginning of your new LaTeX command is not considered part of a word, so \\< will not match.
Try this instead:
(add-hook 'LaTeX-mode-hook
(lambda ()
(font-lock-add-keywords nil
'(("\\(\\\\conceito\\)\\>" 1 font-lock-warning-face t)))
EDIT: Another good observation that Deokhwan Kim made is that in this particular case, you don't really need the parenthesis at all, because you're attempting to match the whole expression anyway. So an alternative to the last line could be:
'(("\\\\conceito\\>" 0 font-lock-warning-face t)))))
The point about the parenthesis is correct, but you could actually extend your regexp to only match when an opening curly brace { follows the word "conceito". But since you don't really want to highlight that brace, using sub-groups defined by parentheses is the way to go:
(add-hook 'LaTeX-mode-hook
(lambda ()
(font-lock-add-keywords nil
'(("\\(\\\\conceito\\)\\s-*{" 1 font-lock-warning-face t)))
Note that since we're testing for a { that follows directly after "conceito" (unless there's whitespace in between), we don't need the test for \\> any more at all.
In general, try M-x re-builder to craft regular expression interactively: you can edit a new regexp in a small buffer and instantly see what is highlighted in the buffer from which you invoked the re-builder.
GNU AUCTeX has a built-in way of defining custom highlighting to user-defined macros. Have a look at the variable font-latex-user-keyword-classes and the AUCTeX documentation.
Here's a simple example (my configuration):
(setq font-latex-user-keyword-classes
'(("shadow-hidden" (("hide" "{")) shadow command)
("shadow-mycomment" (("mycomment" "{")) shadow command)
("shadow-comment" (("comment" "{")) shadow command)))
This will show the contents of \hide{}, \mycomment{}, and \comment{} macros in the dim shadow face.
While this question concerns the formatting of LaTeX within Emacs (and maybe Auctex), I believe this can be applied to more general situations in Emacs concerning delimiters like parentheses, brackets, and braces.
I am looking to be able to do the following with Emacs (and elisp), and don't know where to begin. Say I have:
(This is in parentheses)
With some keybinding in Emacs, I want Emacs to find the matching delimiter to whichever one is by my cursor (something I know Emacs can do since it can highlight matching delimiters in various modes) and be able to change both of them to
\left( This is in parentheses \right)
The delimiters I would like this to work with are: (...), [...], \lvert ... \rvert, \langle ... \rangle, \{ ... \}. What elisp would I need to accomplish this task?
More general ways to handle matching delimiters are welcome.
Evaluate the command below in Emacs. After reloading you can put the point (text cursor) immediately after a closing paren. Then do M-x replace-matching-parens to replace the closing ) with \right) and the matching start paren ( with \left(.
(defun replace-matching-parens ()
(interactive)
(save-excursion
(let ((end-point (point)))
(backward-list)
(let ((start-point (point)))
(goto-char end-point)
(re-search-backward ")" nil t)
(replace-match " \\\\right)" nil nil)
(goto-char start-point)
(re-search-forward "(" nil t)
(replace-match "\\\\left( " nil nil)))))
The interactive bit indicates that I want a "command", so it can be executed using M-x. To avoid the cursor ending up in a strange place after execution I'm wrapping the logic in save-excursion. The point jumps back to the opening paren using backward-list and holds on to the start and end positions of the paren-matched region. Lastly, starting at the end and working backwards I replace the strings. By replacing backwards rather than forwards I avoid invalidating end-point before I need it.
Generalizing this to handle different kinds of delimiters shouldn't be too bad. backward-list ought to work with any pair of strings emacs recognizes as analogues of ( and ). To add more parenthesis-like string pairs, check out set-syntax-table in this Parenthesis Matching article.
Use global-set-key to setup a key binding to replace-matching-parens.
Fair warning: replace-matching-parens is the first elisp command I've implemented, so it may not align with best practices. To all the gurus out there, I'm open to constructive criticism.