[mythtv-users] Emacs mode for myth coding std?

f-myth-users at media.mit.edu f-myth-users at media.mit.edu
Mon Jul 7 19:28:33 UTC 2008


Thanks for sending this!

Some comments:

(setq inhibit-splash-screen t) isn't properly part of changing the
mode.  (Yeah, I know, -everybody- turns this off, but conceptually
it shouldn't be in there if the OP is just asking about myth-mode.)

A more visually compact way to add your hooks (no change in functionality)
which also makes it obvious that all 3 modes are hooked identically:

(c-add-style "myth" myth-c-style nil)

(defun myth-c-hook ()
  (c-set-style "myth"))

(add-hook 'c-mode-common-hook 'myth-c-hook)
(add-hook 'cc-mode-common-hook 'myth-c-hook)
(add-hook 'c++-mode-common-hook 'myth-c-hook)

[It might also be a few bytes more compact because you're not asking
the byte-compiler to produce the same code 3 times---I doubt the elisp
compiler is nearly smart enough to optimize it, though OTOH we're
talking about saving literally only a handful of bytes.]

Note that I haven't actually tested the above.

P.S.  Stylistic note:  most Lisp programmers find unaesthetic the
dangling-paren style (where you're closing a couple parens per line at
the end of an s-expression)---just because C does that with close-braces
isn't a reason Lisp should do it with parens.  There -are- occasional
cases where it makes sense because you're really trying to emphasize
something about the list structure (or because you want to make it
trivial to add extra lines at the very end without moving the rest of
the closing parens down again, e.g., as in your defconst), but usually
all closing parens for a form immediately follow the relevent text of
that line.

(I've been a developer in Lisp since the early 80's, including for a
vendor of Lisp machines, so I've seen an awful lot of Lisp...  and if
you look at the elisp source for most of Emacs, you'll see that it's
rare that dangling parens are used there, too.)

E.g., like this:

(defun foo (bar)
  (cond ((eq bar 'blah)
	 (blarg)
	 (biff))
	(t
	 (quux))))

...and not like this:

(defun foo (bar)
  (cond ((eq bar 'blah)
	 (blarg)
	 (biff))
	(t
	 (quux)
        )
  )
)

But:

(defconst myth-c-style
  '((c-basic-offset . 4)
    (tab-width . 20)
    (indent-tabs-mode . nil)
    (c-comment-only-line-offset . 0)
    (c-hanging-braces-alist     . ((substatement-open before after)))
    (c-offsets-alist . ((topmost-intro        . 0)
			(substatement         . +)
			(substatement-open    . 0)
			(case-label           . +)
			(access-label         . -)
			(inclass              . ++)
			(inline-open          . 0)
			))
  ))

(I've pushed your final two parens together but left them on their own
line, just as the pair above, because in both cases you might want to
add extra elements at the end and this makes it easy without pushing
the parens around any more.)


More information about the mythtv-users mailing list