From 55577e7c020702f5bc8c2ff079baf8839fbccb9b Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 5 Jun 2013 14:10:27 -0400 Subject: [PATCH] * 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. --- lisp/ChangeLog | 6 ++ lisp/loadup.el | 1 + lisp/progmodes/prog-mode.el | 113 ++++++++++++++++++++++++++++++++++++ lisp/simple.el | 75 ------------------------ src/ChangeLog | 4 ++ src/lisp.mk | 1 + 6 files changed, 125 insertions(+), 75 deletions(-) create mode 100644 lisp/progmodes/prog-mode.el diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1338475b8b5..8bf63a4bbb0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-06-05 Stefan Monnier + + * 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 * simple.el (prog-prettify-symbols): Add version. diff --git a/lisp/loadup.el b/lisp/loadup.el index 5764cdec7eb..7fb9526b360 100644 --- a/lisp/loadup.el +++ b/lisp/loadup.el @@ -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") diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el new file mode 100644 index 00000000000..c1e2857eb89 --- /dev/null +++ b/lisp/progmodes/prog-mode.el @@ -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 . + +;;; 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 diff --git a/lisp/simple.el b/lisp/simple.el index e173a32878f..15bf8779f56 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -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)) diff --git a/src/ChangeLog b/src/ChangeLog index ac0563c6bdd..31e21b04eac 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2013-06-05 Stefan Monnier + + * lisp.mk (lisp): Add prog-mode.el. + 2013-06-05 Paul Eggert Chain glib's SIGCHLD handler from Emacs's (Bug#14474). diff --git a/src/lisp.mk b/src/lisp.mk index 174e53ed561..edd81bcf493 100644 --- a/src/lisp.mk +++ b/src/lisp.mk @@ -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 \ -- 2.39.2