Skip to content

Instantly share code, notes, and snippets.

@sensorflo
Forked from swarminglogic/info-mode.el
Last active November 18, 2015 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sensorflo/a6299a9cd0563abdc02d to your computer and use it in GitHub Desktop.
Save sensorflo/a6299a9cd0563abdc02d to your computer and use it in GitHub Desktop.
emacs major mode for Boost PropertyTree INFO file format and parser
;;; info-mode-el -- Major mode for editing boost property tree INFO files.
;; Copyright (C) 2014 Roald Fernandez <contact@swarminglogic.com>
;; Author: Roald Fernandez <contact@swarminglogic.com>
;; URL: https://gist.github.com/swarminglogic/be3cd49fcba5ef891727
;; Created: 10 Nov 2014
;; Keywords: INFO major-mode
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;; This program is distributed in the hope that it will be
;; useful, but WITHOUT ANY WARRANTY; without even the implied
;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;; PURPOSE. See the GNU General Public License for more details.
;; You should have received a copy of the GNU General Public
;; License along with this program; if not, write to the Free
;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
;; MA 02111-1307 USA
;;; Commentary:
;; To use, place a copy of this file in your .emacs.d directory (for
;; example "~/.emacs.d/plugins"), and add the following to your .emacs
;; file:
;;
;; (add-to-list 'load-path "~/.emacs.d/plugins/")
;; (require 'generic-x)
;; (require 'info-mode)
;;
;; This mode will automatically be enabled for file names "*.info"
;;
;; For more information about INFO files, see the boost property tree
;; documentation, chapter INFO parser:
;; http://www.boost.org/doc/libs/1_59_0/doc/html/property_tree/parsers.html
;;; Code:
(defvar info-indent-offset 4
"Indentation offset for `info-mode'.")
(defun generic-indent-line ()
"Indent current line for any balanced-paren-mode'."
(interactive)
(let ((indent-col 0)
(indentation-increasers "[{]")
(indentation-decreasers "[}]")
)
(save-excursion
(beginning-of-line)
(condition-case nil
(while t
(backward-up-list 1)
(when (looking-at indentation-increasers)
(setq indent-col (+ indent-col info-indent-offset))))
(error nil)))
(save-excursion
(back-to-indentation)
(when (and (looking-at indentation-decreasers) (>= indent-col info-indent-offset))
(setq indent-col (- indent-col info-indent-offset))))
(indent-line-to indent-col)))
;;;###autoload
(define-generic-mode 'info-mode
'(";")
'("true" "false")
'(("^[ \t]*\\(#include\\)[ \t]+\\(\"[^\"]*?\"\\)"
(1 font-lock-preprocessor-face)
(2 font-lock-constant-face))
("^[ \t]*\\([^ \t\n\f{}]+\\)[ \t]*\\(?:$\\|{\\)"
(1 font-lock-function-name-face))
("^[ \t]*\\([^ \t\n\f]+\\)[ \t]+\\(\"[^\"]*\"\\|[^{\\\" \t\f\n][^ \t\n\f]*\\)"
(1 font-lock-variable-name-face)
(2 font-lock-constant-face)))
nil
'((lambda ()
(make-local-variable 'info-indent-offset)
(make-local-variable 'generic-indent-line)
(set 'indent-line-function 'generic-indent-line)
))
"Major mode for boost property tree INFO files."
)
;;;###autoload
(add-to-list 'auto-mode-alist (cons "\\.info\\'" 'info-mode))
(provide 'info-mode)
;;; info-mode.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment