Hot answers tagged

6

This seems to work for me: (require 'cc-mode) (setq yashi-font-lock-doc-comments (let ((symbol "[a-zA-Z0-9_-]+")) `((,(concat "`" symbol "'") 0 ,c-doc-markup-face-name prepend nil)) )) (setq yashi-font-lock-keywords `((,(lambda (limit) (c-font-lock-doc-comments "/\\*" limit yashi-font-lock-doc-comments) )))) (...


6

I'm using this yasnippet: # -*- mode: snippet -*- # name: ifndef # key: ifndef # -- #ifndef ${1:`(upcase (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))`_HH_} #define $1 $0 #endif You can quickly customize it to do what you want. In case you're not using yasnippet yet Here's my personal config (you can take the parts that you ...


5

If you use Helm, then yes, there's helm-semantic-or-imenu command. Demo with C: Demo with Emacs Lisp: For Caml and Haskell, you can use this command but there's probably only Imenu support (so you won't get full function interface like the above 2 demos).


3

After fiddling a bit longer with this, I think I figured it out. Adding the following snippet to my CC-mode init-configuration fixed this: (defun my-cc-init-hook () "Initialization hook for CC-mode runs before any other hooks." (setq c-doc-comment-style '((java-mode . javadoc) (pike-mode . autodoc) (c-mode . javadoc) (c++-mode ....


3

You are using the wrong tool. The c-doc system is used to highlight doxygen-style comments, which is why it changes the face from font-lock-comment-face to font-lock-doc-face. Another drawback is that you can only have one doc style, so if you use it to highlight symbols, you can't use it for anything else. Below is code to add a plain font-lock keyword, ...


2

smartparens (and some other "auto pair" packages) allows you to do something similar: (sp-pair "#ifdef" "#endif") This won't easily get you that ending comment like a snippet engine can (I believe it's possible with smartparens, though), but it answers your title so I thought it was close enough to warrant an answer.


1

The "gnu" style sets c-basic-offset to 2, so that's where that's coming from. As you have specific needs for a specific filename extension, I'd probably just define a derived mode to use with auto-mode-alist: (define-derived-mode cuda-mode c-mode "CUDA" "CUDA mode." (setq c-basic-offset 4)) (add-to-list 'auto-mode-alist '("\\.cu\\'" . cuda-mode)) You ...


1

If you want to use an existing solution then you can look into smartparens which seems to be easily extensible, see the pair management section on their wiki. As for your code, it's definitely on the right track, but looking-at looks at text after the point, so the insertion function should rather be something along the lines of (defun close-c-comment () ...


1

The following function transforms unicode strings into literal c-strings. Note however that the transformation is encoding dependent. For interactive use just write your c-string with multibyte characters place point in the string and call M-x string-to-cStr. (require 'seq) (require 'cl-lib) (defun string-to-cStr (string) "Return STRING encoded as ...


1

You have to put a syntax-table property on the ' and " characters, e.g.: (defun c-propertize-@ () (interactive) (save-excursion (goto-char (point-min)) (while (re-search-forward "@\\(\"\\|'\\)" nil t) (put-text-property (match-beginning 1) (match-end 1) 'syntax-table ...


1

The highlighting used is font-lock-doc-face, as the comment begins with ** and emacs recognizes this as javadoc. As you noted, using three stars, ore only one, will cause it to be treated as a regular comment. You can use the shortcut C-u C-x = to get info on the current face, text properties are the last item so you may need to scroll the buffer that ...


1

You can just add the mapping to the comment style list: (add-to-list 'c-doc-comment-style '(c++-mode . javadoc)) This is more portable and just extends the list instead of replacing it.


Only top voted, non community-wiki answers of a minimum length are eligible