Emacs indent-line-function - emacs

i try to indent sql file lines in emacs, I think the c-indent-line is pretty good for me, so i write this code to my init file:
(defun my-sql-mode ()
(setq indent-line-function 'c-indent-line)
)
(add-hook 'sql-mode-hook 'my-sql-mode)
But when i use tab to indent the line, it always give me the tips of 'Wrong type argument: stringp, nil'.
Can someone help me?

Indentation in Emacs is generally intelligent, but it's not magic.
c-indent-line is a function designed for use with C and C++ code. It shouldn't be greatly surprising that it might not work in other contexts, and I'm not sure what you were expecting it to do when faced with SQL code?
I'm afraid the answer is simply: Don't do that.
If you tell us what you wanted it to do, however, someone might be able to help.

Related

What does ad-activate do?

In an answer, I noticed:
;; Align with spaces only
(defadvice align-regexp (around align-regexp-with-spaces)
"Never use tabs for alignment."
(let ((indent-tabs-mode nil))
ad-do-it))
(ad-activate 'align-regexp)
This sounds promising, but... what does it do?!
I tried eval-region on the block of code. But for me, all it does is adding the following to the align-regexp docs:
This function is advised.
Around-advice `align-regexp-with-spaces':
Never use tabs for alignment.
I don't seem to be able to actually use align-regexp-with-spaces, if that's what should be the effect... What am I missing?
I used GNU Emacs version 24.0.96.1 (i386-mingw-nt6.1.7601).
While asking this question, I realized that I just didn't get the idea of advising functions.
It became clear to me that:
align-regexp-with-spaces isn't a function nor a variable but only a name (to enable/disable single pieces of advice)
ever since (ad-activate 'align-regexp), align-regexp just does what I 'advised' it to: not to use tabs
So: ad-activate activates the advice, effectively changing the original function's behavior. Great!
I don't get why this is 'better' than defining a function around align-regexp though. But then again I don't know much about Emacs Lisp.
I'm afraid the extra lines of documentation only added to the confusion...

Trying to edit init.el to customize emacs

So I'm relatively new in trying to customize emacs. But I really need to customize is asap. Tabs are a pain in emacs as they are two spaces, and the text is all messed up when it is opened with any other editor after that.
Currently, I only have few lines in my ~/emacs.d/init.el file:
(setq load-path (concat (getenv "HOME") "/.emacs.d/"))
(set-scroll-bar-mode 'right)
(require 'linum)
(global-linum-mode t)
I get an error while starting up emacs:
Loading encoded-kb...done
An error has occurred while loading `/Users/mycomp/.emacs.d/init.el':
Symbol's function definition is void: set-scroll-bar-mode
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
I tried srtating it with the --debug-init option, but my lisp knowledge is not enough to help me figure out what's wrong. Any help on how to get this working or redirecting me to some GOOD tutorials on editing init.el files will be really helpful (yes i did google tutorials on editing the initialization file, but every one of them was terrible).
I'm assuming my code for getting line numbers on the left is also wrong. Could someone please help me with this? Thanks a lot.
I think this line may be the problem:
(setq load-path (concat (getenv "HOME") "/.emacs.d/"))
First of all, I don't think this is required to load ~/emacs.d/init.el. Secondly, if you do want to add a directory to your load-path, you should probably be doing it like this instead:
(add-to-list 'load-path "~/.emacs.d/")
This code adds the directory to the load-path, your code just clobbers it with the single directory.
Use 'M-x apropos' and 'M-x customize-apropos'. For now, those will make your life much easier when you want to customize things.
For instance, to customize things to do with scrolling, 'M-x customize-apropos RET scroll RET' will give you a list of all things that you can customize that have 'scroll' in them. You can look around and find the things that you want by searching the buffer. If you find a particular thing that you want, there's usually a group that it belongs to. You can click on that, and just customize those particular values. Make sure you save the settings.
It might take you a while to figure out what things are called. If you've got an idea, try the apropos search. If that doesn't turn up anything, google can probably sort it out for you.
For now, don't worry about hacking the elisp. This method will write values to your startup file (probably the .emacs?) and you can look and check the syntax later if you're really interested. I customize most of my stuff this way; I only bother actually modifying the file by hand when I'm trying to write my own hooks or functions.

Why am I getting an elisp error?

I just installed yasnippets and addeded these snippets for latex https://github.com/madsdk/yasnippets-latex/
When I try to expand a snippet like "eq" I get the following:
\begin{equation}
\label{[yas] elisp error!}
\end{equation}
Why is this happening, and how do I fix it?
The debug-on-error didn't do anything, I guess because of the good-grace thing. But turning on reftex-mode fixed the problem.

How to make parenthesis matching work in XEmacs?

I tried using all options in the menu setting Options|Display|Paren Highlighting, but nothing works - no parenthesis match is performed. I also tried setting explicitly (paren-mode 'blink-paren t) in my init file, but that did not help either. Any ideas what may be happening and how do I fix it?
Thanks.
I have had paren mode working long enough in my XEmacs that I forget what exactly I did to turn it on, but I did dig these things out which might help.
From my .xemacs/init.el:
(require 'paren)
From my .xemacs/custom.el as part of custom-set-variables:
'(paren-mode (quote sexp) nil (paren))
'(show-paren-mode t)
-John

Emacs Lisp syntax highlighting

I want to write a syntax highlighting extension for Emacs, but I Googling of variations on "emacs syntax highlight tutorial" have all failed. How do I go about learning how to write an Emacs highlighter? What good resources are there for learning how to do such things?
You're looking in the wrong place. Look at "font-lock-mode".
There's a related question, on how to define a major mode with syntax highlighting using 'define-generic-mode. The question focuses on figuring out how to get the syntax highlighting working.
unfortunately you were searching for the wrong terms, "syntax highlighting" is not emacs vocabulary :). You should have searched for something like "write emacs mode".
There was already a question for this: "How to write an emacs mode for a new language" with some good pointers.
If you are interested in writing your own highlighting, another question covered this and may be of value to you. It included this code snippet:
(defun django-highlight-comments ()
(interactive "p")
(highlight-regexp "{%.*?%}" 'hi-orange))
(add-hook 'html-mode-hook 'django-highlight-comments)
Code courtesy of Ashutosh Mehra's answer.
http://a-kat.com/Emacs_Major_Modes.html