aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2013-06-05 14:10:27 -0400
committerStefan Monnier2013-06-05 14:10:27 -0400
commit55577e7c020702f5bc8c2ff079baf8839fbccb9b (patch)
tree19ca8b290af16a0fa1d5e995eb068d03801b62af
parent8fc57765e8baaf917734997b6bd3ca014613ad65 (diff)
downloademacs-55577e7c020702f5bc8c2ff079baf8839fbccb9b.tar.gz
emacs-55577e7c020702f5bc8c2ff079baf8839fbccb9b.zip
* 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.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/loadup.el1
-rw-r--r--lisp/progmodes/prog-mode.el113
-rw-r--r--lisp/simple.el75
-rw-r--r--src/ChangeLog4
-rw-r--r--src/lisp.mk1
6 files changed, 125 insertions, 75 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 1338475b8b5..8bf63a4bbb0 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12013-06-05 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * simple.el: Move all the prog-mode code to prog-mode.el.
4 * progmodes/prog-mode.el: New file.
5 * loadup.el: Add prog-mode.el.
6
12013-06-05 Teodor Zlatanov <tzz@lifelogs.com> 72013-06-05 Teodor Zlatanov <tzz@lifelogs.com>
2 8
3 * simple.el (prog-prettify-symbols): Add version. 9 * 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 @@
210(load "textmodes/page") 210(load "textmodes/page")
211(load "register") 211(load "register")
212(load "textmodes/paragraphs") 212(load "textmodes/paragraphs")
213(load "progmodes/prog-mode")
213(load "emacs-lisp/lisp-mode") 214(load "emacs-lisp/lisp-mode")
214(load "textmodes/text-mode") 215(load "textmodes/text-mode")
215(load "textmodes/fill") 216(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 @@
1;;; prog-mode.el --- Generic major mode for programming -*- lexical-binding:t -*-
2
3;; Copyright (C) Free Software Foundation, Inc.
4
5;; Maintainer: FSF
6;; Keywords: internal
7;; Package: emacs
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24;;; Commentary:
25
26;; This major mode is mostly intended as a parent of other programming
27;; modes. All major modes for programming languages should derive from this
28;; mode so that users can put generic customization on prog-mode-hook.
29
30;;; Code:
31
32(eval-when-compile (require 'cl-lib))
33
34(defgroup prog-mode nil
35 "Generic programming mode, from which others derive."
36 :group 'languages)
37
38(defvar prog-mode-map
39 (let ((map (make-sparse-keymap)))
40 (define-key map [?\C-\M-q] 'prog-indent-sexp)
41 map)
42 "Keymap used for programming modes.")
43
44(defun prog-indent-sexp (&optional defun)
45 "Indent the expression after point.
46When interactively called with prefix, indent the enclosing defun
47instead."
48 (interactive "P")
49 (save-excursion
50 (when defun
51 (end-of-line)
52 (beginning-of-defun))
53 (let ((start (point))
54 (end (progn (forward-sexp 1) (point))))
55 (indent-region start end nil))))
56
57(defvar prog-prettify-symbols-alist nil)
58
59(defcustom prog-prettify-symbols nil
60 "Whether symbols should be prettified.
61When set to an alist in the form `(STRING . CHARACTER)' it will
62augment the mode's native prettify alist."
63 :type '(choice
64 (const :tag "No thanks" nil)
65 (const :tag "Mode defaults" t)
66 (alist :tag "Mode defaults augmented with your own list"
67 :key-type string :value-type character))
68 :version "24.4")
69
70(defun prog--prettify-font-lock-compose-symbol (alist)
71 "Compose a sequence of ascii chars into a symbol.
72Regexp match data 0 points to the chars."
73 ;; Check that the chars should really be composed into a symbol.
74 (let* ((start (match-beginning 0))
75 (end (match-end 0))
76 (syntaxes (if (eq (char-syntax (char-after start)) ?w)
77 '(?w) '(?. ?\\))))
78 (if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes)
79 (memq (char-syntax (or (char-after end) ?\ )) syntaxes)
80 (nth 8 (syntax-ppss)))
81 ;; No composition for you. Let's actually remove any composition
82 ;; we may have added earlier and which is now incorrect.
83 (remove-text-properties start end '(composition))
84 ;; That's a symbol alright, so add the composition.
85 (compose-region start end (cdr (assoc (match-string 0) alist)))))
86 ;; Return nil because we're not adding any face property.
87 nil)
88
89(defun prog-prettify-font-lock-symbols-keywords ()
90 (when prog-prettify-symbols
91 (let ((alist (append prog-prettify-symbols-alist
92 (if (listp prog-prettify-symbols)
93 prog-prettify-symbols
94 nil))))
95 `((,(regexp-opt (mapcar 'car alist) t)
96 (0 (prog--prettify-font-lock-compose-symbol ',alist)))))))
97
98(defun prog-prettify-install (alist)
99 (setq-local prog-prettify-symbols-alist alist)
100 (let ((keywords (prog-prettify-font-lock-symbols-keywords)))
101 (if keywords (font-lock-add-keywords nil keywords))))
102
103;;;###autoload
104(define-derived-mode prog-mode fundamental-mode "Prog"
105 "Major mode for editing programming language source code."
106 (set (make-local-variable 'require-final-newline) mode-require-final-newline)
107 (set (make-local-variable 'parse-sexp-ignore-comments) t)
108 ;; Any programming language is always written left to right.
109 (setq bidi-paragraph-direction 'left-to-right))
110
111(provide 'prog-mode)
112;; arch-tag: 6f3ded02-6cc9-11d8-b018-000a95e675a6
113;;; 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."
372 "Parent major mode from which special major modes should inherit." 372 "Parent major mode from which special major modes should inherit."
373 (setq buffer-read-only t)) 373 (setq buffer-read-only t))
374 374
375;; Major mode meant to be the parent of programming modes.
376
377(defvar prog-mode-map
378 (let ((map (make-sparse-keymap)))
379 (define-key map [?\C-\M-q] 'prog-indent-sexp)
380 map)
381 "Keymap used for programming modes.")
382
383(defun prog-indent-sexp (&optional defun)
384 "Indent the expression after point.
385When interactively called with prefix, indent the enclosing defun
386instead."
387 (interactive "P")
388 (save-excursion
389 (when defun
390 (end-of-line)
391 (beginning-of-defun))
392 (let ((start (point))
393 (end (progn (forward-sexp 1) (point))))
394 (indent-region start end nil))))
395
396(define-derived-mode prog-mode fundamental-mode "Prog"
397 "Major mode for editing programming language source code."
398 (set (make-local-variable 'require-final-newline) mode-require-final-newline)
399 (set (make-local-variable 'parse-sexp-ignore-comments) t)
400 (make-local-variable 'prog-prettify-symbols-alist)
401 ;; Any programming language is always written left to right.
402 (setq bidi-paragraph-direction 'left-to-right))
403
404(defvar prog-prettify-symbols-alist nil)
405
406(defcustom prog-prettify-symbols nil
407 "Whether symbols should be prettified.
408When set to an alist in the form `(STRING . CHARACTER)' it will
409augment the mode's native prettify alist."
410 :type '(choice
411 (const :tag "No thanks" nil)
412 (const :tag "Mode defaults" t)
413 (alist :tag "Mode defaults augmented with your own list"
414 :key-type string :value-type character))
415 :version "24.4"
416 :group 'languages)
417
418(defun prog--prettify-font-lock-compose-symbol (alist)
419 "Compose a sequence of ascii chars into a symbol.
420Regexp match data 0 points to the chars."
421 ;; Check that the chars should really be composed into a symbol.
422 (let* ((start (match-beginning 0))
423 (end (match-end 0))
424 (syntaxes (if (eq (char-syntax (char-after start)) ?w)
425 '(?w) '(?. ?\\))))
426 (if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes)
427 (memq (char-syntax (or (char-after end) ?\ )) syntaxes)
428 (nth 8 (syntax-ppss)))
429 ;; No composition for you. Let's actually remove any composition
430 ;; we may have added earlier and which is now incorrect.
431 (remove-text-properties start end '(composition))
432 ;; That's a symbol alright, so add the composition.
433 (compose-region start end (cdr (assoc (match-string 0) alist)))))
434 ;; Return nil because we're not adding any face property.
435 nil)
436
437(defun prog-prettify-font-lock-symbols-keywords ()
438 (when prog-prettify-symbols
439 (let ((alist (append prog-prettify-symbols-alist
440 (if (listp prog-prettify-symbols)
441 prog-prettify-symbols
442 nil))))
443 `((,(regexp-opt (mapcar 'car alist) t)
444 (0 (prog--prettify-font-lock-compose-symbol ',alist)))))))
445
446(defun prog-prettify-install (alist)
447 (setq-local prog-prettify-symbols-alist alist)
448 (font-lock-add-keywords nil (prog-prettify-font-lock-symbols-keywords)))
449
450;; Making and deleting lines. 375;; Making and deleting lines.
451 376
452(defvar hard-newline (propertize "\n" 'hard t 'rear-nonsticky '(hard)) 377(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 @@
12013-06-05 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * lisp.mk (lisp): Add prog-mode.el.
4
12013-06-05 Paul Eggert <eggert@cs.ucla.edu> 52013-06-05 Paul Eggert <eggert@cs.ucla.edu>
2 6
3 Chain glib's SIGCHLD handler from Emacs's (Bug#14474). 7 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 = \
129 $(lispsource)/textmodes/page.elc \ 129 $(lispsource)/textmodes/page.elc \
130 $(lispsource)/register.elc \ 130 $(lispsource)/register.elc \
131 $(lispsource)/textmodes/paragraphs.elc \ 131 $(lispsource)/textmodes/paragraphs.elc \
132 $(lispsource)/progmodes/prog-mode.elc \
132 $(lispsource)/emacs-lisp/lisp-mode.elc \ 133 $(lispsource)/emacs-lisp/lisp-mode.elc \
133 $(lispsource)/textmodes/text-mode.elc \ 134 $(lispsource)/textmodes/text-mode.elc \
134 $(lispsource)/textmodes/fill.elc \ 135 $(lispsource)/textmodes/fill.elc \