* lisp/simple.el: Move all the prog-mode code to prog-mode.el.
* lisp/progmodes/prog-mode.el: New file. * lisp/loadup.el: * src/lisp.mk (lisp): Add prog-mode.el.
This commit is contained in:
parent
8fc57765e8
commit
55577e7c02
6 changed files with 125 additions and 75 deletions
|
|
@ -1,3 +1,9 @@
|
|||
2013-06-05 Stefan Monnier <monnier@iro.umontreal.ca>
|
||||
|
||||
* simple.el: Move all the prog-mode code to prog-mode.el.
|
||||
* progmodes/prog-mode.el: New file.
|
||||
* loadup.el: Add prog-mode.el.
|
||||
|
||||
2013-06-05 Teodor Zlatanov <tzz@lifelogs.com>
|
||||
|
||||
* simple.el (prog-prettify-symbols): Add version.
|
||||
|
|
|
|||
|
|
@ -210,6 +210,7 @@
|
|||
(load "textmodes/page")
|
||||
(load "register")
|
||||
(load "textmodes/paragraphs")
|
||||
(load "progmodes/prog-mode")
|
||||
(load "emacs-lisp/lisp-mode")
|
||||
(load "textmodes/text-mode")
|
||||
(load "textmodes/fill")
|
||||
|
|
|
|||
113
lisp/progmodes/prog-mode.el
Normal file
113
lisp/progmodes/prog-mode.el
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
;;; prog-mode.el --- Generic major mode for programming -*- lexical-binding:t -*-
|
||||
|
||||
;; Copyright (C) Free Software Foundation, Inc.
|
||||
|
||||
;; Maintainer: FSF
|
||||
;; Keywords: internal
|
||||
;; Package: emacs
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
;; GNU Emacs 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 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This major mode is mostly intended as a parent of other programming
|
||||
;; modes. All major modes for programming languages should derive from this
|
||||
;; mode so that users can put generic customization on prog-mode-hook.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(eval-when-compile (require 'cl-lib))
|
||||
|
||||
(defgroup prog-mode nil
|
||||
"Generic programming mode, from which others derive."
|
||||
:group 'languages)
|
||||
|
||||
(defvar prog-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(define-key map [?\C-\M-q] 'prog-indent-sexp)
|
||||
map)
|
||||
"Keymap used for programming modes.")
|
||||
|
||||
(defun prog-indent-sexp (&optional defun)
|
||||
"Indent the expression after point.
|
||||
When interactively called with prefix, indent the enclosing defun
|
||||
instead."
|
||||
(interactive "P")
|
||||
(save-excursion
|
||||
(when defun
|
||||
(end-of-line)
|
||||
(beginning-of-defun))
|
||||
(let ((start (point))
|
||||
(end (progn (forward-sexp 1) (point))))
|
||||
(indent-region start end nil))))
|
||||
|
||||
(defvar prog-prettify-symbols-alist nil)
|
||||
|
||||
(defcustom prog-prettify-symbols nil
|
||||
"Whether symbols should be prettified.
|
||||
When set to an alist in the form `(STRING . CHARACTER)' it will
|
||||
augment the mode's native prettify alist."
|
||||
:type '(choice
|
||||
(const :tag "No thanks" nil)
|
||||
(const :tag "Mode defaults" t)
|
||||
(alist :tag "Mode defaults augmented with your own list"
|
||||
:key-type string :value-type character))
|
||||
:version "24.4")
|
||||
|
||||
(defun prog--prettify-font-lock-compose-symbol (alist)
|
||||
"Compose a sequence of ascii chars into a symbol.
|
||||
Regexp match data 0 points to the chars."
|
||||
;; Check that the chars should really be composed into a symbol.
|
||||
(let* ((start (match-beginning 0))
|
||||
(end (match-end 0))
|
||||
(syntaxes (if (eq (char-syntax (char-after start)) ?w)
|
||||
'(?w) '(?. ?\\))))
|
||||
(if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes)
|
||||
(memq (char-syntax (or (char-after end) ?\ )) syntaxes)
|
||||
(nth 8 (syntax-ppss)))
|
||||
;; No composition for you. Let's actually remove any composition
|
||||
;; we may have added earlier and which is now incorrect.
|
||||
(remove-text-properties start end '(composition))
|
||||
;; That's a symbol alright, so add the composition.
|
||||
(compose-region start end (cdr (assoc (match-string 0) alist)))))
|
||||
;; Return nil because we're not adding any face property.
|
||||
nil)
|
||||
|
||||
(defun prog-prettify-font-lock-symbols-keywords ()
|
||||
(when prog-prettify-symbols
|
||||
(let ((alist (append prog-prettify-symbols-alist
|
||||
(if (listp prog-prettify-symbols)
|
||||
prog-prettify-symbols
|
||||
nil))))
|
||||
`((,(regexp-opt (mapcar 'car alist) t)
|
||||
(0 (prog--prettify-font-lock-compose-symbol ',alist)))))))
|
||||
|
||||
(defun prog-prettify-install (alist)
|
||||
(setq-local prog-prettify-symbols-alist alist)
|
||||
(let ((keywords (prog-prettify-font-lock-symbols-keywords)))
|
||||
(if keywords (font-lock-add-keywords nil keywords))))
|
||||
|
||||
;;;###autoload
|
||||
(define-derived-mode prog-mode fundamental-mode "Prog"
|
||||
"Major mode for editing programming language source code."
|
||||
(set (make-local-variable 'require-final-newline) mode-require-final-newline)
|
||||
(set (make-local-variable 'parse-sexp-ignore-comments) t)
|
||||
;; Any programming language is always written left to right.
|
||||
(setq bidi-paragraph-direction 'left-to-right))
|
||||
|
||||
(provide 'prog-mode)
|
||||
;; arch-tag: 6f3ded02-6cc9-11d8-b018-000a95e675a6
|
||||
;;; prog-mode.el ends here
|
||||
|
|
@ -372,81 +372,6 @@ Other major modes are defined by comparison with this one."
|
|||
"Parent major mode from which special major modes should inherit."
|
||||
(setq buffer-read-only t))
|
||||
|
||||
;; Major mode meant to be the parent of programming modes.
|
||||
|
||||
(defvar prog-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(define-key map [?\C-\M-q] 'prog-indent-sexp)
|
||||
map)
|
||||
"Keymap used for programming modes.")
|
||||
|
||||
(defun prog-indent-sexp (&optional defun)
|
||||
"Indent the expression after point.
|
||||
When interactively called with prefix, indent the enclosing defun
|
||||
instead."
|
||||
(interactive "P")
|
||||
(save-excursion
|
||||
(when defun
|
||||
(end-of-line)
|
||||
(beginning-of-defun))
|
||||
(let ((start (point))
|
||||
(end (progn (forward-sexp 1) (point))))
|
||||
(indent-region start end nil))))
|
||||
|
||||
(define-derived-mode prog-mode fundamental-mode "Prog"
|
||||
"Major mode for editing programming language source code."
|
||||
(set (make-local-variable 'require-final-newline) mode-require-final-newline)
|
||||
(set (make-local-variable 'parse-sexp-ignore-comments) t)
|
||||
(make-local-variable 'prog-prettify-symbols-alist)
|
||||
;; Any programming language is always written left to right.
|
||||
(setq bidi-paragraph-direction 'left-to-right))
|
||||
|
||||
(defvar prog-prettify-symbols-alist nil)
|
||||
|
||||
(defcustom prog-prettify-symbols nil
|
||||
"Whether symbols should be prettified.
|
||||
When set to an alist in the form `(STRING . CHARACTER)' it will
|
||||
augment the mode's native prettify alist."
|
||||
:type '(choice
|
||||
(const :tag "No thanks" nil)
|
||||
(const :tag "Mode defaults" t)
|
||||
(alist :tag "Mode defaults augmented with your own list"
|
||||
:key-type string :value-type character))
|
||||
:version "24.4"
|
||||
:group 'languages)
|
||||
|
||||
(defun prog--prettify-font-lock-compose-symbol (alist)
|
||||
"Compose a sequence of ascii chars into a symbol.
|
||||
Regexp match data 0 points to the chars."
|
||||
;; Check that the chars should really be composed into a symbol.
|
||||
(let* ((start (match-beginning 0))
|
||||
(end (match-end 0))
|
||||
(syntaxes (if (eq (char-syntax (char-after start)) ?w)
|
||||
'(?w) '(?. ?\\))))
|
||||
(if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes)
|
||||
(memq (char-syntax (or (char-after end) ?\ )) syntaxes)
|
||||
(nth 8 (syntax-ppss)))
|
||||
;; No composition for you. Let's actually remove any composition
|
||||
;; we may have added earlier and which is now incorrect.
|
||||
(remove-text-properties start end '(composition))
|
||||
;; That's a symbol alright, so add the composition.
|
||||
(compose-region start end (cdr (assoc (match-string 0) alist)))))
|
||||
;; Return nil because we're not adding any face property.
|
||||
nil)
|
||||
|
||||
(defun prog-prettify-font-lock-symbols-keywords ()
|
||||
(when prog-prettify-symbols
|
||||
(let ((alist (append prog-prettify-symbols-alist
|
||||
(if (listp prog-prettify-symbols)
|
||||
prog-prettify-symbols
|
||||
nil))))
|
||||
`((,(regexp-opt (mapcar 'car alist) t)
|
||||
(0 (prog--prettify-font-lock-compose-symbol ',alist)))))))
|
||||
|
||||
(defun prog-prettify-install (alist)
|
||||
(setq-local prog-prettify-symbols-alist alist)
|
||||
(font-lock-add-keywords nil (prog-prettify-font-lock-symbols-keywords)))
|
||||
|
||||
;; Making and deleting lines.
|
||||
|
||||
(defvar hard-newline (propertize "\n" 'hard t 'rear-nonsticky '(hard))
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
2013-06-05 Stefan Monnier <monnier@iro.umontreal.ca>
|
||||
|
||||
* lisp.mk (lisp): Add prog-mode.el.
|
||||
|
||||
2013-06-05 Paul Eggert <eggert@cs.ucla.edu>
|
||||
|
||||
Chain glib's SIGCHLD handler from Emacs's (Bug#14474).
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@ lisp = \
|
|||
$(lispsource)/textmodes/page.elc \
|
||||
$(lispsource)/register.elc \
|
||||
$(lispsource)/textmodes/paragraphs.elc \
|
||||
$(lispsource)/progmodes/prog-mode.elc \
|
||||
$(lispsource)/emacs-lisp/lisp-mode.elc \
|
||||
$(lispsource)/textmodes/text-mode.elc \
|
||||
$(lispsource)/textmodes/fill.elc \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue