How to keep cpp-mode indenting while I use another mode in Emacs? - emacs

I use a custom mode for a certain type of files just for syntax highlighting. But c-style indentation does not work when I load that mode. I don't want to write the rules for indentation for this mode.
Here is the link for the mode I'm using
How can I use the Emacs default c-style indentation in this custom mode?
Thanks.

c-mode installs its own parser to calculate indentation. Therefore, switching on c-indentation is not as simple as it seems to be (you cannot simply set indent-line-function and indent-region-function).
You can try the following:
(add-hook 'ned-mode-hook (lambda ()
(c-init-language-vars c-mode)
(c-basic-common-init 'c-mode "user")))
I noticed regular expressions for comments and strings in ned-font-lock-keywords. As far as I understand font-lock, this is wrong. Comments and strings are handled by the Parse-Partial-Sexp parser (see syntax-ppss) and not via regular expressions.
Furthermore, ned-mode should be derived from prog-mode and not from text-mode.

Related

Is there a way to disable indentation for one specific org-mode src block at a time?

I'm using most of the standard features of org-mode that come with the spacemacs develop branch, but I haven't been able to find a way to disable the automatic indentation for source code blocks on a case by case basis. I use tangle and I'm writing Dockerfile's in the same file that I'm writing groovy code or javascript for example. The Dockerfile's are the only ones I want not to be indented so I can get syntax highlighting. Here's what it looks like without the indentation:
And here's what it looks like with the indentation that automatically happens if I edit the text:
The automatic indentation is fine for groovy for example, so I have no issue with the automatic indentation here. (in fact, if I still got the syntax highlighting for Dockerfile's I probably wouldn't mind too much except the weird word wrapping not respecting the background face). Here's the example with groovy:
As you can see, I tried a :noindent property I found in the org-mode docs that's usually in a #+STARTUP directive. I also searched stack overflow, but I didn't find anything fruitful that didn't disable indenting for all source blocks or for the entire file.
In my practice (I'm not sure it is a good practice or not, just share it to you):
I setup org-src-tab-acts-natively to true for using the language’s major-mode indentation. In your case, it will format the src block with the formatting rules of dockerfile-mode.
I created a new major-mode plain-mode for the content which should not be indented automatically. Personally, I use this mode for something like:
shell outputs
ASCII diagrams
...
#+begin_src plain
this will not
be
auto
indented
#+end_src
Above src block will not be indented when you select them as region, and TAB on them.
In this way, the src blocks will always behavior as expected when formatting them.
Aside, the example code of plain-mode:
(define-derived-mode plain-mode
clean-mode "Plain"
"Major mode for plain text."
;; preserve the auto indentation on line
(setq-local indent-line-function 'indent-relative)
;; disable auto indentation on region
(setq-local indent-region-function (lambda (start end))))

How to use emacs/elisp to highlight parts of font-locked source code

I have some log files that contain the directory paths and file names (and line numbers) for C++, C, Java and C# source code files. I have written a regex to search for these file names and line numbers and open the source code file and position the insertion point at the specified line number (kinda like the next-error function when used with the compile command).
Given a file name that appears in the log file multiple times I want to add highlighting (and selectively remove highlighting) to the source code file display window/buffer.
I can do this with functions like add-text-properties, remove-text-properties and add-face-text-property (where is remove-face-text-property?) if there is no font-lock (keyword color coding). These functions don't work if font-lock is turned on!
How do I do this if the font-lock is turned on? I see that the incremental search feature does it so it is possible to add and remove highlighting with out messing up the font-lock coding.
Thanks
Siegfried
Use overlays instead of text-properties. E.g. to highlight with face bold the text between BEG and END, do something like:
(let ((ol (make-overlay BEG END)))
(overlay-put ol 'face 'bold))
Any highlighting that uses text property face is overruled by font-lock highlighting -- font-lock wants to win. In many cases you can still highlight text, but sooner or later font-lock erases that highlighting when it refontifies the buffer.
This does not apply to highlighting that uses overlays –- font-lock has no effect on overlays. So one answer is to just use overlays. However, if that does not work for your use case (there are some downsides to using overlays) there is still hope.
To prevent the interference of font-lock with other highlighting, the typical Emacs approach is to fool font-lock into thinking that it is font-lock highlighting, even when it does not involve font-lock-keywords.
But this has the effect that such highlighting is turned off when font-lock-mode is turned off. Whether this is a good thing or bad depends on your use case.
In vanilla Emacs you have no choice about this. Either the highlighting is not recognized by font-lock, which overrules it, or it is recognized as “one of its own”, in which case it is turned off when font-lock highlighting is turned off.
If you don't need your special highlighting when font-lock-mode is turned off, then you can just use text property font-lock-face instead of property face.
If you use library highlight.el to implement your highlighting then you can do that just by leaving option hlt-face-prop at its default value of font-lock-face. (Value font-lock-face means that the highlighting is controlled by font-lock. Value face means that font-lock does not recognize the highlighting.)
For the case where the option value is face, if you also use library font-lock+.el then there is no interference by font-lock –- the highlighting is independent of font-lock.
Library font-lock+.el is loaded automatically by highlight.el, if it is in your load-path. It prevents font-locking from removing any highlighting face properties that you apply using the commands defined here.
See Highlight Library for more information.

emacs cedet (semantic) how to remove hyphenate function decoration

Thanks to this post, I was able to remove some of the ugly underlining semantic utilizes with it's inline parsing, but I still have a hyphen appearing at each of my function calls (and sometimes else where) that I would really like to remove. How can I do this? I have also looked through http://www.gnu.org/software/emacs/manual/html_mono/semantic.html#Tag-Decoration-Mode.
Reference image:
I'd suggest looking at your CEDET config instead.
You're probably calling semantic-load-enable-excessive-code-helpers.
And this function got its name for a reason.
So instead of enabling a function that has excessive it its name,
and then trying to remove the excessive features, why not just stick with the basics?
Just to show you my CEDET setup:
(load "~/git/cedet/cedet-devel-load")
(add-to-list 'semantic-lex-c-preprocessor-symbol-file
"~/Software/deal.II/include/deal.II/base/config.h")
(semantic-add-system-include "~/Software/deal.II/include/" 'c++-mode)
(set-default 'semantic-case-fold t)
(semantic-mode 1)
But if there some extra cool functionality that
only semantic-load-enable-excessive-code-helpers provides, please let me know.
It turns out that the hyphen was part of the semantic tag folding mode, which functions to collapse and expand code blocks in the gui version of emacs. I am not sure the same functionality is achieved in the terminal interface; but regardless, to remove these hyphens from my code, all I had to do was turn off
(global-semantic-tag-folding-mode)

Re-filling entire paragraph automatically with auto-fill-mode?

Motivation: Using the defaults, Auto Fill mode seems not as useful as I might
have hoped: If I insert a sentence in the middle of a paragraph, only the current
line is re-filled. When I insert a sentence, I want the entire paragraph to be re-filled.
Question: How can I set auto-fill-function (or perhaps
normal-auto-fill-function) in my .emacs
file so that the paragraph is re-filled whenever a single line overflows?
I tried setting it to fill-paragraph, but then I cannot insert any spaces at the end of a paragraph (e.g., to add another word).
More details: I primarily use Auto Fill mode in the AUCTeX major mode for LaTeX.
The built-in Emacs documentation for auto-fill-mode states:
When auto-fill-mode is on, the auto-fill-function variable is
non-nil.
The value of normal-auto-fill-function specifies the function to use
for auto-fill-function when turning Auto Fill mode on.
The documentation for the normal-auto-fill-function variable
says that it is the function to use for auto-fill-function if Auto Fill mode is
turned on, and that the initial value is do-auto-fill.
You might like to try refill-mode. But in general, it's just tricky to make such a feature work well. Another approach is to only do the refill as part of the redisplay (i.e. without affecting the buffer's actual content). For that, try setting word-wrap or enabling visual-line-mode.
For LaTeX files you can try (requires AUCTeX)
(add-hook 'LaTeX-mode-hook '(lambda ()
(setq auto-fill-function 'LaTeX-fill-paragraph)))
but use it with caution.

Font-locking for SQL-MODE inside of ORG-MODE not font-locking

Related to question: org-mode: fontify code blocks natively
I've got the latest org-mode and emacs versions as of November 1, 2012 (org stored in org-20121105).
I've also got the sql-mode that comes with emacs-24.
I've got fontification turned one:
;; fontify code in code blocks
(setq org-src-fontify-natively t)
Yet this does not fontify in my org documents. Java, bash, etc. all work.
#+BEGIN_SRC SQL
SELECT foo FROM bar
#+END_SRC
When I open a file foobar.sql, the mode indicator says SQL[ANSI] (which I also tried as the source type), and font-locking works.
Thanks in advance for any tips.
Firstly, the name of the SRC block mode is case-sensitive. It should be sql instead of SQL.
#+BEGIN_SRC sql
SELECT foo FROM bar
#+END_SRC
Secondly, the initial font-lock of sql-mode seams not to highlight SQL keywords, (at least to me, it looks no difference no matter you turn it on or off). Therefore, you need to specify which kind of SQL you want to highlight. If you are using MySQL for example:
(add-hook 'sql-mode-hook
(lambda ()
(sql-highlight-mysql-keywords)))
Then Restart Emacs. It should work now.
Oh, wait, try putting #+BEGIN_SRC sql in lower case. See here for identifiers.
Try refreshing the display, by making the block be reparsed (break the syntax and undo, or something). It often happens to me with python or bibtex blocks, but this fixes it.
I can't see why it wouldn't fontify inline if it finds the right mode when you C-c '.
Also, I'm afraid fontification, while being one of org-mode's nicer features, is not exactly perfectly handled. From the mailing list :
The fontification engine is not very powerful and get easily fooled.