Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
;; clu-mode-boaz.el ;; ;; Modified clu mode for GNU Emacs ;; dbplass, 3/8/89; makes clu mode be auto-fill automatically. ;; 4/12/89 Added _ and $ to syntax table. ;; Added clu-line-tab, bound to M-Tab ;; (S.Blau, Feb. 1987) ;; (defvar clu-mode-syntax-table nil "Syntax table used while in clu mode.") (if (null clu-mode-syntax-table) (let ((st (syntax-table))) (unwind-protect (progn (setq clu-mode-syntax-table (make-syntax-table)) (set-syntax-table clu-mode-syntax-table) (modify-syntax-entry ?[ "(] ") (modify-syntax-entry ?] ")[ ") (modify-syntax-entry ?{ "(} ") (modify-syntax-entry ?} "){ ") (modify-syntax-entry ?\" "\" ") (modify-syntax-entry ?' "\" ") (modify-syntax-entry ?_ ". ") ;underscore is delimeter (modify-syntax-entry ?% "< ") (modify-syntax-entry ?\n "> ") (modify-syntax-entry ?\$ ". ")) ;$ is delimeter (set-syntax-table st)))) (defvar clu-mode-map nil "keymap used in clu-mode") (if (not clu-mode-map) (progn (setq clu-mode-map (make-sparse-keymap)) (define-key clu-mode-map "\t" 'clu-tab) (define-key clu-mode-map "\r" 'clu-ret) (define-key clu-mode-map "\C-xc" 'clu-compile) (define-key clu-mode-map "\^x\^k" 'kill-compilation) (define-key clu-mode-map "\M-\C-i" 'clu-line-tab))) (defun clu-mode () "Clu-sux-mode is for editing clu-sux programs. TAB at beginning of line reindents; with prefix-arg all following lines will be reindented; this is unfortunately very slow since CLU SUCKS. RET new-line-and-indent C-x C runs interactive Clu-sux compiler. ^X` finds next error message ^X^K kills compiler Variables controlling indentation style: clu-indent If nil, turns off automatic language directed indent. Default is t. clu-indent-size Each indentation level offsets text by this much. Default is 4. clu-cluster-indent If nil, turns off indent for cluster and guardian bodies. Default is t. clu-except-offset Extra indentation for line beginning with except-statement. Default is 1. clu-when-offset Extra indentation for line beginning with when-statement. Default is -1." (interactive) (kill-all-local-variables) (use-local-map clu-mode-map) (setq mode-name "Clu-Sux") (auto-fill-mode 1) ;;Turn on auto-fill mode (setq major-mode 'clu-mode) (set-syntax-table clu-mode-syntax-table) (define-abbrev-table 'clu-mode-abbrev-table ()) (setq local-abbrev-table clu-mode-abbrev-table) (make-local-variable 'indent-line-function) (setq indent-line-function 'clu-indent-line) (make-local-variable 'comment-start) (setq comment-start "%") (make-local-variable 'comment-column) (setq comment-column 40) (make-local-variable 'last-filename) ;For incremental error parsing (setq last-filename nil) ;; Variables used by external compile program (make-local-variable 'name-of-mode) (setq name-of-mode "compilation") (make-local-variable 'compile-command) (setq compile-command (concat "clu " (file-name-nondirectory buffer-file-name))) ;;Execute usr's mode-hook if hook defined and not nil (and (boundp 'clu-mode-hook) clu-mode-hook (funcall clu-mode-hook))) (defvar clu-mode-abbrev-table nil "Abbrev table in use in Clu-mode buffers.") (defvar clu-indent t "*If non-nil TAB and RET will automatically indent") (defvar clu-indent-size 5 "*Each indentation level offsets text by this much") (defvar clu-cluster-indent t "*If nil cluster bodies will not be indented") (defvar clu-except-offset 2 "*Extra indentation for except-statement") (defvar clu-when-offset -2 "*Extra indentation for when-statement") (defun clu-module (string) "Expands current word to a template for a module" (let (id) (beginning-of-line) (setq id (buffer-substring (point) (progn (skip-chars-forward "^ \t$") (point)))) (end-of-line) (insert-string (concat " = " string " ()\n")) (clu-indent-line) (insert-string (concat "end " id))) (skip-chars-backward "^\(")) (defun clu-line-tab (&optional argp) "Go to beginning of line, indent current line, return cursor to point." (interactive "P") (if (not clu-indent) (insert ?\t) ; if not beginning of line, or not clu-indent mode, ; just insert the tab character. (save-excursion ; return to same point afterwards (beginning-of-line) (if (not argp) ; i.e. only one line (clu-indent-line) ;indent current line (message "Reindent started...") (set-mark (point)) ; indent a whole LOTTA lines. (while (< (point) (point-max)) (clu-indent-line) (forward-line 1)) (goto-char (mark)) (message "Reindent done..."))))) (defun clu-tab (&optional argp) "Indent current line if point is at beginning of line, else insert tab." (interactive "P") (if (or (not (bolp)) (not clu-indent)) (insert ?\t) ; if not beginning of line, or not clu-indent mode, ; just insert the tab character. (beginning-of-line) (if (not argp) ; i.e. only one line (clu-indent-line) ;indent current line (message "Reindent started...") (set-mark (point)) ; indent a whole LOTTA lines. (while (< (point) (point-max)) (clu-indent-line) (forward-line 1)) (goto-char (mark)) (message "Reindent done...")))) (defun clu-ret () "Newline and indent" (interactive) (if (not clu-indent) (newline) (newline) (clu-indent-line))) (defun clu-indent-line (&optional whole-exp) "Indent current line as Clu code. Argument means shift any additional lines of grouping rigidly with this line." (interactive "P") (delete-horizontal-space) (indent-to (calculate-clu-indent))) (defun even (number) ;returns true if number is even, false otherwise (= 0 (mod number 2))) (defun calculate-clu-indent (&optional parse-start) "Return appropriate indentation for current line as Clu code." (let ((count 0) (count1 0) (col 0) (end-of-line-pos 0) (single-quote 0) (double-quote 0)) (progn (save-excursion (beginning-of-line) (if (eq (point) (point-min)) ;first line in file nil (backward-word 1) (end-of-line) (setq end-of-line-pos (point)) (beginning-of-line) ;; Preset column to current indentation (setq col (current-indentation)) (while (not (= (following-char) ?\n)) (cond ( (= (following-char) ?\') (setq single-quote (1+ single-quote))) ( (= (following-char) ?\") (setq double-quote (1+ double-quote))) ( (and (= (following-char) ?%) (even double-quote) (even single-quote)) (progn (end-of-line) (backward-char 1))) ;; if a percent follows, go to end of line ;; and back one char ( (= (following-char) ?\() (setq count (1+ count))) ;; open paren means indent one level in ( (= (following-char) ?\)) (setq count (1- count))) ;; close paren means indent one level out ( (looking-at "=[ \t]*") ; equals, then space or TAB (progn ;; If looking at equals then WS, ;; see what we're defining ;; look at first non equals or WS char (skip-chars-forward "= \t") ;; if iter or proc then move one level in (if (or (looking-at "iter") (looking-at "proc") (and clu-cluster-indent (looking-at "cluster"))) (setq count (1+ count))))) ;; if preceding char was space or tab, ;; look at current command ( (if (or (= (preceding-char) ? ) (= (preceding-char) ?\t)) (progn ;; if curr. command is for, if while etc. ;; indent one level in; end, indent one level out (if (or (looking-at "for[ \t\n(]+") (looking-at "if[ \t\n(]+") (looking-at "while") (looking-at "begin") (looking-at "except") (looking-at "tagcase") (looking-at "tag")) (setq count (1+ count)) (if (looking-at "end[ \t\n]+") (setq count (1- count)))))))) (forward-char 1)) (beginning-of-line) (skip-chars-forward " \t") (cond ((looking-at "except") (setq col (- col clu-except-offset))) ((looking-at "else") (setq col (- col -2))) ((looking-at "when") (setq col (- col clu-when-offset)))) (end-of-line) (forward-word 1) (beginning-of-line) (forward-to-indentation 0) (cond ((looking-at "except") (setq col (+ col clu-except-offset))) ((looking-at "else") (setq col (+ col -2))) ((looking-at "when") (setq col (+ col clu-when-offset))))) (+ col (* count clu-indent-size)))))) (defun clu-compile () "Compile the Clu-program in the current buffer" (interactive) (if (and (boundp 'compilation-process) compilation-process (eq (process-status compilation-process) 'run)) (let* ((buf (process-buffer compilation-process)) (cbuf (current-buffer))) (call-interactively 'clu-command) (pop-to-buffer buf) (set-window-start (get-buffer-window buf) (- (point) 12)) (pop-to-buffer cbuf)) (call-interactively 'compile) (if compilation-process (progn (save-excursion (set-buffer (process-buffer compilation-process)) (clu-compilation-mode)) (set-process-filter compilation-process 'clu-filter))))) (defvar clu-regexp "\\(^Compiling[ a-zA-Z0-9/\.]+\\)\\|\\(^[0-9]+:\\)\\|\\(^command\(s\):\\)" "Regular expression for filename-lines and error-msg-lines") (defun clu-filter (proc string) "This gets called with each string the compiler outputs" (save-window-excursion (set-buffer (process-buffer proc)) ;(if (bolp) (forward-line 2)) (goto-char (point-max)) (let ((save-pos (point)) save-pos2 save-pos3) ;(goto-char (point-max)) (insert-string string) (goto-char save-pos) (while (re-search-forward clu-regexp nil t) (setq save-pos2 (match-beginning 0)) (setq save-pos3 (match-end 0)) (save-excursion (goto-char (match-beginning 0)) (cond ((looking-at "[0-9]+:") (skip-chars-forward "^ \t") (insert-string "\n ") (goto-char save-pos2) (insert-string (concat last-filename ", line "))) ((looking-at "command\(s\):") (goto-char (point-max)) (ding) (message "Clu compiler ready to receive new command\(s\)...")) ((looking-at "Compiling") (goto-char save-pos3) (skip-chars-backward "^ \n") (setq last-filename (buffer-substring (point) (progn (skip-chars-forward "^\ $") (point)))))))) ;remove \r before \n (goto-char save-pos) (while (re-search-forward "\ " nil t) (delete-backward-char 1))) (goto-char (point-max)))) (defun clu-command (command) "This gets called to prompt and get command for running compiler" (interactive (list (read-input "Clu command\(s\): " ""))) (send-string compilation-process (concat command "\n"))) ;; ;; ;; clu-compilation-mode ;; ;; (defvar clu-compilation-mode nil) (defvar clu-compilation-mode-map nil) ;(defvar clu-save-buffer nil) (if (not clu-compilation-mode-map) (progn (setq clu-compilation-mode-map (make-sparse-keymap)) (define-key clu-compilation-mode-map "\e&" 'clu-compilation-go-end) (define-key clu-compilation-mode-map "\r" 'clu-compilation-command))) (defun clu-compilation-mode () "string+RET at end of file after the text \"command\(s\):\" is interpreted as a command to the clu-compiler" (interactive) ;(kill-all-local-variables) (use-local-map clu-compilation-mode-map) ;(setq clu-save-buffer (current-buffer)) (setq mode-name "clu-compilation") (setq major-mode 'clu-compilation-mode)) (defun clu-compilation-command () "This gets called when RET-key is input to *compilation* buffer" (interactive) (skip-chars-forward " \t") (if (not (equal (point) (point-max))) (insert-string "\n") (skip-chars-backward "^:") (set-mark (point)) (setq command (buffer-substring (point) (progn (skip-chars-forward "^$") (point)))) (goto-char (mark)) (delete-region (point) (point-max)) ;(save-excursion ; (beginning-of-line) ; (set-window-start ; (get-buffer-window (current-buffer)) (point))) (send-string compilation-process (concat command "\n")))) (defun clu-compilation-go-end () "This gets called on C-x c" (interactive) (goto-char (point-max))) ; (setq compile-command "clu #externals false #locals false #optimize time\n")