LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-25-2014, 07:35 PM   #1
stateless
Member
 
Registered: Jan 2013
Distribution: Debian
Posts: 166
Blog Entries: 1

Rep: Reputation: 4
emacs: customizing font-lock-faces for a specific mode?


In my office, I'm the closest thing we have to an Emacs guru. Recently somebody was asking if it was possible to customize how a mode looks for a specific programming languages. From what I understand, the various major modes use font-lock, so one can customize them all at once through customizing the Font Lock Faces group. But I wouldn't know how to do that for only a single major mode. Any insight...?
 
Old 02-27-2014, 03:33 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,968
Blog Entries: 13

Rep: Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007
One option to consider if you don't know the variety of settings, but wish to view the results per file type is from within emacs:

Options --> Customize Emacs --> Browse Customization Groups

Under there you'll see something similar too:
Code:
`Raised' text indicates buttons; type RET or click mouse-1
on a button to invoke its action.
Invoke [+] to expand a group, and [-] to collapse an expanded group.
Invoke the [Group], [Face], and [Option] buttons below to edit that
item in another window.

[-]-\ Group Emacs
   [+]-- Group Editing
   [+]-- Group External
   [+]-- Group Convenience
   [+]-- Group Programming
   [+]-- Group Applications
   [+]-- Group Development
   [+]-- Group Environment
   [+]-- Group Data
   [+]-- Group Files
   [+]-- Group Wp
   [+]-- Group Faces
   [+]-- Group Hypermedia
   [+]-- Group Help
   [+]-- Group Multimedia
   [+]-- Group Local
   [+]-- Group Epg
   [+]-- Group PostScript
And if you expand Programming and further Languages, you'll see something like:
Code:
   [-]-\ Group Programming
    | [-]-\ Group Languages
    |  | [+]-- Group Lisp
    |  | [+]-- Group C
    |  | [+]-- Group Postscript
    |  | [+]-- Group Ada
    |  | [+]-- Group Antlr
    |  | [+]-- Group Asm
    |  | [+]-- Group Cfengine
    |  | [+]-- Group Cperl
    |  | [+]-- Group Css
    |  | [+]-- Group Dcl
    |  | [+]-- Group Delphi
    |  | [+]-- Group F90
    |  | [+]-- Group Fortran
    |  | [+]-- Group Hideshow
    |  | [+]-- Group Icon
    |  | [+]-- Group IDLWAVE
    |  | [+]-- Group Info Lookup
    |  | [+]-- Group Ld Script
    |  | [+]-- Group M4
    |  | [+]-- Group Meta Font
    |  | [+]-- Group Modula2
    |  | [+]-- Group Nxml
    |  | [+]-- Group Octave
    |  | [+]-- Group Pascal
    |  | [+]-- Group Perl
    |  | [+]-- Group Prolog
    |  | [+]-- Group Python
    |  | [+]-- Group Relax Ng
    |  | [+]-- Group Sgml
    |  | [+]-- Group Sh
    |  | [+]-- Group Sieve
    |  | [+]-- Group Simula
    |  | [+]-- Group Tcl
    |  | [+]-- Group Vera
    |  | [+]-- Group Verilog Mode
    |  | [+]-- Group Vhdl
Explore the settings per language (i.e. major mode) and then save your customizations. You can then view the .emacs file and see how those changes were implemented and consider even further customization once you understand which option and variable names control the behaviors you desire to be set up in a certain way.

For instance, here is a copy of the C Language group settings available from my version, which I think is 23.4.
Code:
Editing a setting changes only the text in this buffer.
To apply your changes, use the Save or Set buttons.
Saving a change normally works by editing your init file.
For details, see Saving Customizations in the Emacs manual.


 Operate on all settings in this buffer that are not marked HIDDEN:
 Set for current session Save for future sessions
 Undo edits Reset to saved Erase customizations   Exit

Parent groups: Languages

/- C group: Support for the C language and related languages.------------\
      State: visible group members are all at standard values.
      See also Manual and Font Lock Faces group.

C Strict Syntax P: Hide Value Toggle  off (nil)
   State: STANDARD.
   If non-nil, all syntactic symbols must be found in `c-offsets-alist'. More

C Echo Syntactic Information P: Hide Value Toggle  off (nil)
   State: STANDARD.
   If non-nil, syntactic info is echoed when the line is indented.

C Report Syntactic Errors: Hide Value Toggle  off (nil)
   State: STANDARD.
   If non-nil, certain syntactic errors are reported with a ding More

C Basic Offset: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Amount of basic offset used by + and - symbols in `c-offsets-alist'. More

C Tab Always Indent: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Controls the operation of the TAB key. More

C Insert Tab Function: Hide Value insert-tab
   State: STANDARD.
   Function used when inserting a tab for M-x c-indent-command. More

C Syntactic Indentation: Hide Value Toggle  on (non-nil)
   State: STANDARD.
   Whether the indentation should be controlled by the syntactic context. More

C Syntactic Indentation In Macros: Hide Value Toggle  on (non-nil)
   State: STANDARD.
   Enable syntactic analysis inside macros. More

C Comment Only Line Offset: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Extra offset for line which contains only the start of a comment. More

C Indent Comment Alist: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Specifies how M-x indent-for-comment calculates the comment start column. More

C Indent Comments Syntactically P: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Specifies how M-x indent-for-comment should handle comment-only lines. More

C Block Comment Prefix: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Specifies the line prefix of continued C-style block comments. More

C Comment Prefix Regexp: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Regexp to match the line prefix inside comments. More

C Doc Comment Style: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Specifies documentation comment style(s) to recognize. More

C Ignore Auto Fill: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   List of contexts in which automatic filling never occurs. More

C Cleanup List: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   List of various C/C++/ObjC constructs to "clean up". More

C Hanging Braces Alist: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Controls the insertion of newlines before and after braces More

C Max One Liner Length: Hide Value 80
   State: STANDARD.
   Maximum length of line that clean-up "one-liner-defun" will compact to. More

C Hanging Colons Alist: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Controls the insertion of newlines before and after certain colons. More

C Hanging Semi&Comma Criteria: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   List of functions that decide whether to insert a newline or not. More

C Backslash Column: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Minimum alignment column for line continuation backslashes. More

C Backslash Max Column: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Maximum alignment column for line continuation backslashes. More

C Auto Align Backslashes: Hide Value Toggle  on (non-nil)
   State: STANDARD.
   Align automatically inserted line continuation backslashes. More

C Backspace Function: Hide Value backward-delete-char-untabify
   State: STANDARD.
   Function called by `c-electric-backspace' when deleting backwards.

C Delete Function: Hide Value delete-char
   State: STANDARD.
   Function called by `c-electric-delete-forward' when deleting forwards.

C Require Final Newline: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Controls whether a final newline is ensured when the file is saved. More

C Electric Pound Behavior: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   List of behaviors for electric pound insertion. More

C Special Indent Hook: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Hook for user defined special indentation adjustments. More

C Label Minimum Indentation: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Minimum indentation for lines inside code blocks. More

C Progress Interval: Hide Value 5
   State: STANDARD.
   Interval used to update progress status during long re-indentation. More

C Objc Method Arg Min Delta To Bracket: Hide Value 2
   State: STANDARD.
   Minimum number of chars to the opening bracket. More

C Objc Method Arg Unfinished Offset: Hide Value 4
   State: STANDARD.
   Offset relative to bracket if first selector is on a new line. More

C Objc Method Parameter Offset: Hide Value 4
   State: STANDARD.
   Offset for selector parameter on a new line (relative to first selector. More

C Default Style: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Style which gets installed by default when a file is visited. More

C Offsets Alist: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Association list of syntactic element symbols and indentation offsets. More

C Style Variables Are Local P: Hide Value Toggle  on (non-nil)
   State: STANDARD.
   Whether style variables should be buffer local by default. More

C Mode Hook: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Hook called by `c-mode'.

C++ Mode Hook: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Hook called by `c++-mode'.

Objc Mode Hook: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Hook called by `objc-mode'.

Java Mode Hook: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Hook called by `java-mode'.

Idl Mode Hook: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Hook called by `idl-mode'.

Pike Mode Hook: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Hook called by `pike-mode'.

Awk Mode Hook: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Hook called by `awk-mode'.

C Mode Common Hook: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Hook called by all CC Mode modes for common initializations.

C Initialization Hook: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   Hook called when the CC Mode package gets initialized. More

C Enable Xemacs Performance Kludge P: Hide Value Toggle  off (nil)
   State: STANDARD.
   Enables a XEmacs only hack that may improve speed for some coding styles. More

C Font Lock Extra Types: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   List of extra types (aside from the type keywords) to recognize in C mode. More

C++ Font Lock Extra Types: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   List of extra types (aside from the type keywords) to recognize in C++ mode. More

Objc Font Lock Extra Types: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   List of extra types (aside from the type keywords) to recognize in ObjC mode. More

Java Font Lock Extra Types: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   List of extra types (aside from the type keywords) to recognize in Java mode. More

Idl Font Lock Extra Types: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   List of extra types (aside from the type keywords) to recognize in IDL mode. More

Pike Font Lock Extra Types: Show Value
   State: HIDDEN, invoke "Show" in the previous line to show.
   List of extra types (aside from the type keywords) to recognize in Pike mode. More

C Macro : Expand C macros in a region.

Cpp : Highlight or hide text according to cpp conditionals.

Hide Ifdef : Hide selected code within `ifdef'.

\- C group end ---------------------------------------------------------/
And, I really didn't read those, I don't know/care much about what they designate, I do write code in C and C++ and if/when emacs doesn't do what I want it to do; such as indent xx spaces, or use tabs instead of spaces, I customize that one behavior and leave it alone, but also keep my profile so I can re-use it. Learning literally every single setting/customization for emacs is, I think; I ton of inefficient use of time.

I will also say to be cautious with your charity. Perhaps learn enough to teach others, rather than be the expert. I've seen coders argue left and right about indentation rules, or where the braces go, or worse ... key mappings for commands. One of them likes select/cut(copy)/paste using the mouse, the other likes to use the keys to do that. Emacs allows for all of that and they're best at learning how to customize their selves, with you providing a basic guide and a golden .emacs file which they can start with. Otherwise, you'll be the center of their constant pestering for changes and customizations.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Emacs - changing default font size and font type? neilcpp Linux - Software 16 05-20-2013 11:29 AM
LXer: Customizing emacs for development LXer Syndicated Linux News 0 03-28-2012 09:20 AM
emacs: minor mode font-mode-lock not on by default?! hewsonism Linux - Newbie 2 06-10-2010 01:32 PM
Automatic hs-minor-mode in Emacs for PHP mode? CoderMan Programming 1 06-12-2009 09:38 AM
Emacs customization questions. (font, color, identation, C/C++-specific) ErV Linux - Software 6 04-16-2007 04:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration