Useful Blog Comments
Nachopp demonstrates some emacs lisp that inserts a commonly used find command in a shell buffer. And Ian Eure has a great follow-up comment which demonstrates the more typical way of defining emacs lisp functions; talks about alternatives such as abbrev mode and yasnippet and finally mentions the best solution, the built-in rgrep.
Defining C++ styles
David Ha has a gallery of some of the built-in C++ styles. None of the styles suit me exactly so I have accreted a fair amount of C++ configuration code over the years. I must admit, I haven’t audited for ages so I’m not sure which bits are necessary and which are not.
(defconst *my-cc-style* '((c-basic-offset . 4) (c-comment-only-line-offset . 0) (c-hanging-braces-alist . ((brace-list-open) (brace-entry-open) (substatement-open after) (block-close . c-snug-do-while))) (c-cleanup-list . (brace-else-brace)) (c-offsets-alist . ((statement-block-intro . +) (knr-argdecl-intro . 0) (substatement-open . 0) (substatement-label . 0) (innamespace . 0) (case-label . +) (statement-cont . +))))) (defun my-c-initialization-hook () (define-key c-mode-base-map "\C-m" 'c-context-line-break) (define-key c-mode-base-map (kbd "RET") 'newline-and-indent) (define-key c-mode-base-map [f7] 'run-compile)) (add-hook 'c-initialization-hook 'my-c-initialization-hook) (setq c-offsets-alist '((member-init-intro . ++))) (c-add-style "PERSONAL" *my-cc-style*) (defun my-c-mode-common-hook () (c-set-style "PERSONAL") (setq tab-width 4 indent-tabs-mode nil c-hungry-delete-key t) (c-toggle-auto-newline 1)) (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
The most useful commands for finding out which of the variables to set are C-c C-o (c-set-offset) and C-c C-s (c-show-syntactic-information)
This is kinda interesting where Ronnie Collinson (from the NotThinking blog)
removes the *compilation* buffer if the compile is successful. It isn’t something I personally would use as I like the feedback, but I wasn’t previously thinking about compilation-finish-functions and I have a few ideas of things I would like to run after a successful compile.
Perennial Emacs Blog Topics
There are a few perennial blog topics in the emacs world – I mentioned a smooth scrolling post in my links from 2009/17 and here is Da Zhang’s take (does anyone like the default behaviour by the way?). I included a link to a post on the incredibly useful mark ring in emacs-links-2009-09 and here is another from yesterday.
Proposed solutions – fix the smooth scrolling behaviour so it works nicely out of the box and… well, perhaps blogs are not a great way of educating the masses after all. Pity.
Thanks for mentioning my post! As you pointed out, searching for solutions on line is not a easy job, especially when the solutions are scattered out on the web.
Hi Zhangda, no worries – I think you did a nice job of summarizing it. And yes, it is hard to know what to do about the documentation situation. But I’m thinking about it.
Thanks, for the acknowledgment, Im supprised any one was reading my site tbh, then again it showed up it the emacs – wordpress rss feed.
Hi Ronnie,
I try to point out interesting emacs related posts in these bi-weekly posts. And yes, I found it on the emacs/wordpress feed.
I have some horrible hacks for setting c-style. I still need to
reach the nirvana point of it doing the correct thing whatever code
base I happen to be working on at the time. So far I’ve had limited
success with guessing the style.
Hi Alex,
I think that messing around with the style configurations is how many people start eh?
Do you have any code you could share?
Thanks
Sure. I won’t post the thing up here though. You can see my-c-mode.el at:
http://github.com/stsquad/my-emacs-stuff/blob/a45c64a1cc730a612ca71532f9c90c9237c12009/my-c-mode.el
my-c-style-guesser just does a simple alist search for a given style. It should probably behave better when it fails to find one.
Hi Alex, thanks for sharing. I like the way you select between different styles depending on the path – nice.
what is the “run-compile” thing in the line
(define-key c-mode-base-map [f7] ‘run-compile))