Mercurial > hg > xemacs-beta
annotate netinstall/simpsock.cc @ 4697:0d6d0edf1253
lisp beginning-end-of-defun-function Changelog entry
hg diff
diff -r ecc468b62551 lisp/ChangeLog
--- a/lisp/ChangeLog Mon Sep 21 21:40:35 2009 +0200
+++ b/lisp/ChangeLog Tue Sep 22 21:11:51 2009 +0200
@@ -1,3 +1,12 @@ 2009-09-20 Aidan Kehoe <kehoea@parhasa
+2009-09-22 Andreas Roehler <andreas.roehler@online.de>
+
+ * lisp.el (beginning-of-defun-raw):
+ new variable: beginning-of-defun-function,
+ beginning-of-defun may call FUNCTION determining start position
+ * lisp.el (end-of-defun):
+ new variable: end-of-defun-function,
+ end-of-defun may call FUNCTION determining the end position
+
;;;;;;;;;;;;;;;;;;;;;;;;
hg diff -p -r 4695 -r 4696
diff -r fee33ab25966 -r ecc468b62551 lisp/lisp.el
--- a/lisp/lisp.el Sun Sep 20 23:50:05 2009 +0100
+++ b/lisp/lisp.el Mon Sep 21 21:40:35 2009 +0200
@@ -155,6 +155,21 @@ Negative arg -N means kill N sexps after
(interactive "p")
(kill-sexp (- (or arg 1))))
+
+;; derived stuff from GNU Emacs
+(defvar beginning-of-defun-function nil
+ "If non-nil, function for `beginning-of-defun-raw' to call.
+This is used to find the beginning of the defun instead of using the
+normal recipe (see `beginning-of-defun'). Modes can define this
+if defining `defun-prompt-regexp' is not sufficient to handle the mode's
+needs.")
+
+(defvar end-of-defun-function nil
+ "If non-nil, function for `end-of-defun' to call.
+This is used to find the end of the defun instead of using the normal
+recipe (see `end-of-defun'). Modes can define this if the
+normal method is not appropriate.")
+
(defun beginning-of-defun (&optional arg)
"Move backward to the beginning of a defun.
With argument, do it that many times. Negative arg -N
@@ -175,13 +190,17 @@ This is identical to beginning-of-defun,
This is identical to beginning-of-defun, except that point does not move
to the beginning of the line when `defun-prompt-regexp' is non-nil."
(interactive "p")
- (and arg (< arg 0) (not (eobp)) (forward-char 1))
- (and (re-search-backward (if defun-prompt-regexp
- (concat "^\\s(\\|"
- "\\(" defun-prompt-regexp "\\)\\s(")
- "^\\s(")
- nil 'move (or arg 1))
- (progn (goto-char (1- (match-end 0)))) t))
+ ;; (and arg (< arg 0) (not (eobp)) (forward-char 1))
+ (unless arg (setq arg 1))
+ (cond
+ (beginning-of-defun-function
+ (funcall beginning-of-defun-function arg))
+ (t (re-search-backward (if defun-prompt-regexp
+ (concat "^\\s(\\|"
+ "\\(" defun-prompt-regexp "\\)\\s(")
+ "^\\s(")
+ nil 'move (or arg 1))
+ (progn (goto-char (1- (match-end 0)))) t)))
;; XEmacs change (optional buffer parameter)
(defun buffer-end (arg &optional buffer)
@@ -198,6 +217,10 @@ the open-parenthesis that starts a defun
;; XEmacs change (for zmacs regions)
(interactive "_p")
(if (or (null arg) (= arg 0)) (setq arg 1))
+ (if end-of-defun-function
+ (if (> arg 0)
+ (dotimes (i arg)
+ (funcall end-of-defun-function)))
(let ((first t))
(while (and (> arg 0) (< (point) (point-max)))
(let ((pos (point))) ; XEmacs -- remove unused npos.
@@ -229,7 +252,7 @@ the open-parenthesis that starts a defun
(if (looking-at "\\s<\\|\n")
(forward-line 1)))
(goto-char (point-min)))))
- (setq arg (1+ arg)))))
+ (setq arg (1+ arg))))))
(defun mark-defun ()
"Put mark at end of this defun, point at beginning.
author | Andreas Roehler <andreas.roehler@online.de> |
---|---|
date | Tue, 22 Sep 2009 21:14:03 +0200 |
parents | 3078fd1074e8 |
children |
rev | line source |
---|---|
448 | 1 /* |
2 * Copyright (c) 2000, Red Hat, Inc. | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * A copy of the GNU General Public License can be found at | |
10 * http://www.gnu.org/ | |
11 * | |
12 * Written by DJ Delorie <dj@cygnus.com> | |
13 * | |
14 */ | |
15 | |
16 /* Simplified socket access functions */ | |
17 | |
18 #include "win32.h" | |
19 #include <winsock.h> | |
20 #include <stdio.h> | |
21 #include <stdarg.h> | |
22 #include <stdlib.h> | |
23 | |
24 #include "simpsock.h" | |
25 #include "msg.h" | |
26 | |
27 #define SSBUFSZ 1024 | |
28 | |
29 SimpleSocket::SimpleSocket (char *hostname, int port) | |
30 { | |
31 static int initted = 0; | |
32 if (!initted) | |
33 { | |
34 initted = 1; | |
35 WSADATA d; | |
36 WSAStartup (MAKEWORD (1,1), &d); | |
37 } | |
38 | |
39 s = INVALID_SOCKET; | |
40 buf = (char *) malloc (SSBUFSZ + 3); | |
41 putp = getp = 0; | |
42 | |
43 int i1, i2, i3, i4; | |
44 unsigned char ip[4]; | |
45 | |
46 if (sscanf (hostname, "%d.%d.%d.%d", &i1, &i2, &i3, &i4) == 4) | |
47 { | |
48 ip[0] = i1; | |
49 ip[1] = i2; | |
50 ip[2] = i3; | |
51 ip[3] = i4; | |
52 } | |
53 else | |
54 { | |
55 struct hostent *he; | |
56 he = gethostbyname (hostname); | |
57 if (!he) | |
58 { | |
59 msg ("Can't resolve `%s'\n", hostname); | |
60 return; | |
61 } | |
62 memcpy (ip, he->h_addr_list[0], 4); | |
63 } | |
64 | |
65 s = socket (AF_INET, SOCK_STREAM, 0); | |
66 if (s == INVALID_SOCKET) | |
67 { | |
68 msg ("Can't create socket, %d", WSAGetLastError ()); | |
69 return; | |
70 } | |
71 | |
72 struct sockaddr_in name; | |
73 | |
74 memset (&name, 0, sizeof (name)); | |
75 name.sin_family = AF_INET; | |
76 name.sin_port = htons (port); | |
77 memcpy (&name.sin_addr, ip, 4); | |
78 | |
79 if (connect (s, (sockaddr *)&name, sizeof(name))) | |
80 { | |
81 msg ("Can't connect to %s:%d", hostname, port); | |
82 closesocket (s); | |
83 s = INVALID_SOCKET; | |
84 return; | |
85 } | |
86 | |
87 return; | |
88 } | |
89 | |
90 SimpleSocket::~SimpleSocket () | |
91 { | |
92 if (s != INVALID_SOCKET) | |
93 closesocket (s); | |
94 s = INVALID_SOCKET; | |
95 if (buf) | |
96 free (buf); | |
97 buf = 0; | |
98 } | |
99 | |
100 int | |
101 SimpleSocket::ok () | |
102 { | |
103 if (s == INVALID_SOCKET) | |
104 return 0; | |
105 return 1; | |
106 } | |
107 | |
108 int | |
109 SimpleSocket::printf (char *fmt, ...) | |
110 { | |
111 char localbuf[SSBUFSZ]; | |
112 va_list args; | |
113 va_start (args, fmt); | |
114 vsprintf (localbuf, fmt, args); | |
115 return send (s, localbuf, strlen (localbuf), 0); | |
116 } | |
117 | |
118 int | |
119 SimpleSocket::write (char *localbuf, int len) | |
120 { | |
121 return send (s, localbuf, len, 0); | |
122 } | |
123 | |
124 int | |
125 SimpleSocket::fill () | |
126 { | |
127 if (putp == getp) | |
128 putp = getp = 0; | |
129 | |
130 int n = SSBUFSZ - putp; | |
131 if (n == 0) | |
132 return 0; | |
133 int r = recv (s, buf + putp, n, 0); | |
134 if (r > 0) | |
135 { | |
136 putp += r; | |
137 return r; | |
138 } | |
139 return 0; | |
140 } | |
141 | |
142 char * | |
143 SimpleSocket::gets () | |
144 { | |
145 if (getp > 0 && putp > getp) | |
146 { | |
147 memmove (buf, buf+getp, putp-getp); | |
148 putp -= getp; | |
149 getp = 0; | |
150 } | |
151 if (putp == getp) | |
152 fill(); | |
153 | |
154 // getp is zero, always, here, and putp is the count | |
155 char *nl; | |
156 while ((nl = (char *)memchr (buf, '\n', putp)) == NULL && putp < SSBUFSZ) | |
157 if (fill () <= 0) | |
158 break; | |
159 | |
160 if (nl) | |
161 { | |
162 getp = nl - buf + 1; | |
163 while ((*nl == '\n' || *nl == '\r') && nl >= buf) | |
164 *nl-- = 0; | |
165 } | |
166 else | |
167 { | |
168 getp = putp; | |
169 nl = buf + putp; | |
170 nl[1] = 0; | |
171 } | |
172 | |
173 return buf; | |
174 } | |
175 | |
176 #define MIN(a,b) ((a) < (b) ? (a) : (b)) | |
177 | |
178 int | |
179 SimpleSocket::read (char *ubuf, int ulen) | |
180 { | |
181 int n, rv=0; | |
182 if (putp > getp) | |
183 { | |
184 n = MIN (ulen, putp-getp); | |
185 memmove (ubuf, buf+getp, n); | |
186 getp += n; | |
187 ubuf += n; | |
188 ulen -= n; | |
189 rv += n; | |
190 } | |
191 while (ulen > 0) | |
192 { | |
193 n = recv (s, ubuf, ulen, 0); | |
194 if (n <= 0) | |
195 return rv; | |
196 ubuf += n; | |
197 ulen -= n; | |
198 rv += n; | |
199 } | |
200 return rv; | |
201 } |