-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathc-syntax-commands.lisp
144 lines (122 loc) · 5.08 KB
/
c-syntax-commands.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
;;; -*- Mode: Lisp; Package: CLIMACS-C-SYNTAX; -*-
;;; (c) copyright 2004-2005 by
;;; Robert Strandh ([email protected])
;;; (c) copyright 2004-2005 by
;;; Elliott Johnson ([email protected])
;;; (c) copyright 2005 by
;;; Matthieu Villeneuve ([email protected])
;;; (c) copyright 2005 by
;;; Aleksandar Bakic ([email protected])
;;; (c) copyright 2006 by
;;; Troels Henriksen ([email protected])
;;; (c) copyright 2007 by
;;; John Q. Splittist ([email protected])
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Library General Public
;;; License as published by the Free Software Foundation; either
;;; version 2 of the License, or (at your option) any later version.
;;;
;;; This library 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
;;; Library General Public License for more details.
;;;
;;; You should have received a copy of the GNU Library General Public
;;; License along with this library; if not, write to the
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;;; Boston, MA 02111-1307 USA.
;;; Commands specific to the C syntax for Climacs.
(in-package :climacs-c-syntax)
;;; This command table is used when Drei runs as a pane.
(make-command-table 'pane-c-table
:errorp nil)
(defmethod additional-command-tables append ((drei drei-pane) (command-table c-table))
'(pane-c-table))
;; Movement commands.
(drei-commands:define-motion-commands expression c-table)
;; (drei-commands:define-motion-commands definition c-table)
(drei-commands:define-motion-commands up c-table
:noun "nesting level up"
:plural "levels")
(drei-commands:define-motion-commands down c-table
:noun "nesting level down"
:plural "levels")
(drei-commands:define-motion-commands list c-table)
(drei-commands:define-editing-commands expression c-table)
(drei-commands:define-deletion-commands expression c-table)
(define-command (com-fill-paragraph :name t :command-table c-table)
()
"Fill paragraph at point. Will have no effect unless there is a
string at point."
(let* ((pane (current-window))
(buffer (buffer pane))
(implementation (implementation buffer))
(syntax (syntax buffer))
(token (form-around syntax (offset (point pane))))
(fill-column (auto-fill-column pane))
(tab-width (tab-space-count (stream-default-view pane))))
(when (form-string-p token)
(with-accessors ((offset1 start-offset)
(offset2 end-offset)) token
(fill-region (make-instance 'standard-right-sticky-mark
:buffer implementation
:offset offset1)
(make-instance 'standard-right-sticky-mark
:buffer implementation
:offset offset2)
#'(lambda (mark)
(syntax-line-indentation mark tab-width syntax))
fill-column
tab-width
syntax
t)))))
(define-command (com-indent-expression :name t :command-table c-table)
((count 'integer :prompt "Number of expressions"))
(let* ((pane (current-window))
(point (point pane))
(mark (clone-mark point))
(syntax (syntax (buffer pane))))
(if (plusp count)
(loop repeat count do (forward-expression mark syntax))
(loop repeat (- count) do (backward-expression mark syntax)))
(indent-region pane (clone-mark point) mark)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Gesture bindings
(set-key 'com-fill-paragraph
'c-table
'((#\q :meta)))
(set-key `(com-indent-expression ,*numeric-argument-marker*)
'c-table
'((#\q :meta :control)))
(set-key `(com-backward-up ,*numeric-argument-marker*)
'c-table
'((#\u :control :meta)))
(set-key `(com-forward-down ,*numeric-argument-marker*)
'c-table
'((#\d :control :meta)))
(set-key `(com-backward-expression ,*numeric-argument-marker*)
'c-table
'((#\b :control :meta)))
(set-key `(com-forward-expression ,*numeric-argument-marker*)
'c-table
'((#\f :control :meta)))
;; (set-key `(com-backward-definition ,*numeric-argument-marker*)
;; 'c-table
;; '((#\a :control :meta)))
;; (set-key `(com-forward-definition ,*numeric-argument-marker*)
;; 'c-table
;; '((#\e :control :meta)))
(set-key `(com-forward-list ,*numeric-argument-marker*)
'c-table
'((#\n :control :meta)))
(set-key `(com-backward-list ,*numeric-argument-marker*)
'c-table
'((#\p :control :meta)))
(set-key `(com-kill-expression ,*numeric-argument-marker*)
'c-table
'((#\k :control :meta)))
(set-key `(com-transpose-expressions)
'c-table
'((#\t :control :meta)))