📄 matlab-eei.el
字号:
(set-face-foreground 'matlab-eei-provisional-breakpoint-marker (car val)) (set-face-background 'matlab-eei-provisional-breakpoint-marker (cdr val)) (set-default sym val)))(defcustom matlab-eei-debug-cursor-type (list "arrow") "Type of cursor used to indicate the line where the debugger hashalted execution of the current M function. The arrow method displaysan arrow at the beginning of the line. In Emacs 21, the arrow appearsin the window gutter. In older versions, the arrow is a text arrow (=>)that overlays and obscures the first two characters of the line. Thehighlight method highlights the line at which execution is stopped.Use " :group 'matlab :type '(list (radio-button-choice (const "arrow") (const "highlight"))))(defvar matlab-eei-highlight-cursor (if (featurep 'xemacs) (make-extent 1 1) (make-overlay 0 0)) "Highlight cursor.")(defcustom matlab-eei-highlight-cursor-color (cons "black" "yellow")"*Specifies the foreground and background colors of the debugger'shighlight-style debug cursor." :group 'matlab :type '(cons (string :tag "Foreground Color") (string :tag "Background Color")) :set '(lambda (sym val) (make-face 'matlab-eei-highlight-cursor-face) (set-face-foreground 'matlab-eei-highlight-cursor-face (car val)) (set-face-background 'matlab-eei-highlight-cursor-face (cdr val)) (if (featurep 'xemacs) (progn (set-extent-face matlab-eei-highlight-cursor 'matlab-eei-highlight-cursor-face) (set-extent-priority matlab-eei-highlight-cursor 98)) (progn (overlay-put matlab-eei-highlight-cursor 'face 'matlab-eei-highlight-cursor-face) (overlay-put matlab-eei-highlight-cursor 'priority 99))) (set-default sym val)))(defvar matlab-eei-matlab-in-debug-mode-p nil "Non-nil if MATLAB is running in debug mode.")(defvar matlab-eei-matlab-stopped-p nil "Non-nil if MATLAB is stopped.")(defun matlab-eei-debug-mode-status (status) "Sets debug mode status flag to STATUS." (message "debug mode status %s" status) (setq matlab-eei-matlab-in-debug-mode-p status));; +----------------------------------------+;; | Breakpoints |;; +----------------------------------------+(defvar matlab-eei-breakpoints nil"Current breakpoints.")(defun matlab-eei-breakpoint-set-face (marker face) "Apply FACE to MARKER." (if (featurep 'xemacs) (progn (set-extent-face marker face) (set-extent-priority marker 98)) (progn (overlay-put marker 'face face) (overlay-put marker 'priority 98))))(defun matlab-eei-is-breakpoint-marker-p (marker) "Return t if MARKER is a breakpoint marker (overlay or extent)." (let ((marker-face (if (featurep 'xemacs) (extent-property marker 'face nil) (overlay-get marker 'face)))) (or (eq marker-face 'matlab-eei-breakpoint-marker) (eq marker-face 'matlab-eei-provisional-breakpoint-marker))))(defun matlab-eei-breakpoint-marker-create (&optional file line) "Create a breakpoint marker at LINE in FILE." (save-excursion ;; Switch to buffer containing new breakpoint, if necessary. (if file (let ((buf (find-buffer-visiting file))) (if (not (eq buf (current-buffer))) (set-buffer buf)))) (if line (goto-line line)) (if (featurep 'xemacs) (make-extent (line-beginning-position) (line-end-position)) (make-overlay (line-beginning-position) (line-end-position) (current-buffer) nil t))))(defun matlab-eei-breakpoint-marker-remove (&optional file line) "Remove breakpoint marker at LINE in FILE." (save-excursion ;; Switch to buffer containing new breakpoint, if necessary. (if file (let ((buf (find-buffer-visiting file))) (if (not (eq buf (current-buffer))) (set-buffer buf)))) (if line (goto-line line)) (if (featurep 'xemacs) (let ((extents (extents-at (line-beginning-position)))) (while extents (let ((extent (car extents))) (if (matlab-eei-is-breakpoint-marker-p extent) (delete-extent extent))) (setq extents (cdr extents)))) (let ((overlays (overlays-at (line-beginning-position)))) (while overlays (let ((overlay (car overlays))) (if (matlab-eei-is-breakpoint-marker-p overlay) (delete-overlay overlay))) (setq overlays (cdr overlays)))))))(defvar matlab-eei-breakpoints-alist nil"List of current breakpoints.")(defun matlab-eei-breakpoints-add (file line &optional provisional-p) "Add the breakpoint at LINE in FILE to the list of current breakpointsstored in `matlab-eei-breakpoints-alist'. PROVISIONAL-P indicates whetherthe breakpoint is provisional, i.e., because FILE is dirty. EEI usesa different face to highlight a provisional breakpoint." (let ((marker (matlab-eei-breakpoint-marker-create file line))) (matlab-eei-breakpoint-set-face marker (if provisional-p 'matlab-eei-provisional-breakpoint-marker 'matlab-eei-breakpoint-marker)) (setq matlab-eei-breakpoints-alist (append matlab-eei-breakpoints-alist (list (cons (if (eq system-type 'windows-nt) (downcase file) file) marker))))))(defun matlab-eei-breakpoint-confirm-add (file line) "Confirm the provisional breakpoint at LINE in FILE by changing its face to the standard breakpoint face." (let ((bp (matlab-eei-breakpoint-exists-p file line))) (if bp (matlab-eei-breakpoint-set-face (cdr bp) 'matlab-eei-breakpoint-marker)))) (defun matlab-eei-breakpoint-set-invisible (file line) "Make the breakpoint at LINE in FILE invisible." (let ((bp (matlab-eei-breakpoint-exists-p file line))) (if bp (matlab-eei-breakpoint-set-face (cdr bp) nil))))(defun matlab-eei-marker-line (marker) "Get the number of the line containing marker." (matlab-eei-get-line-at-point (if (featurep 'xemacs) (extent-start-position marker) (overlay-start marker))))(defun matlab-eei-breakpoints-delete (file line) "Delete the breakpoint at LINE in FILE." (setq matlab-eei-breakpoints-alist (remove-if (lambda (xbp) (let ((xfile (car xbp)) (xmarker (cdr xbp))) (and (string= file xfile) (equal line (matlab-eei-marker-line xmarker))))) matlab-eei-breakpoints-alist)) (matlab-eei-breakpoint-marker-remove file line))(defun matlab-eei-breakpoints-clear () "Clear all breakpoints from all buffers." (mapc (lambda (bpspec) (let* ((file (car bpspec)) (buf (find-buffer-visiting file))) (if buf (save-excursion (set-buffer buf) (let ((line (matlab-eei-marker-line (cdr bpspec)))) (matlab-eei-breakpoint-marker-remove file line)))))) matlab-eei-breakpoints-alist) (setq matlab-eei-breakpoints-alist nil)) (defun matlab-eei-breakpoint-exists-p (file line) "Returns breakpoint if breakpoint exists at FILE and LINE." (find-if (lambda (xbp) (and (string= (car xbp) file) (equal (matlab-eei-marker-line (cdr xbp)) line))) matlab-eei-breakpoints-alist))(defun matlab-eei-get-line-at-point (&optional pos) (let* ((point (or pos (point))) (ln (if (= point 1) 1 (count-lines (point-min) point)))) (save-excursion (goto-char point) (if (eq (char-before) ?\n) (1+ ln) ln))))(defun matlab-eei-request-set-breakpoint (file line) "If the current buffer is not modified, ask MATLAB to seta breakpoint at the current line. Otherwise, cache the requestuntil the user saves the buffer." ;;(message "event: bp at %s %s" file line) (if (not (buffer-modified-p)) (matlab-eei-send-mcmd (format "request_set_breakpoint %s %d" file line) t) (matlab-eei-breakpoints-add file line t)) ;; (message "bp alist %s" (pp-to-string matlab-eei-breakpoints-alist)) )(defun matlab-eei-event-set-breakpoint (file line) "Handle a set breakpoint event from the MATLAB debugger." ;; (message "event set bp: %s %s" file line) (if (and (not matlab-eei-go-until-cursor-mode-p) ;; Ignore if file is currently not open. (find-buffer-visiting file)) (matlab-eei-breakpoints-add file line)) (setq matlab-eei-last-event "set-breakpoint"))(defun matlab-eei-request-clear-breakpoint (file line) "Send a command to MATLAB requesting that the breakpointat LINE in FILE be cleared." (if (buffer-modified-p) (matlab-eei-breakpoints-delete file line) (matlab-eei-send-mcmd (format "request_clear_breakpoint %s %d" file line))))(defun matlab-eei-event-clear-breakpoint (file line) "Handle a request to clear the breakpoint at LINE fromthe M-file FILE." (matlab-eei-breakpoints-delete file line))(defun matlab-eei-breakpoint-set-clear() "Request MATLAB to set a breakpoint at the current lineor clear the existing breakpoint in the current buffer." (interactive);; (matlab-run-in-matlab-mode-only (if (buffer-file-name) (let* ((file (if (eq system-type 'windows-nt) (downcase (buffer-file-name)) (buffer-file-name))) (line (matlab-eei-get-line-at-point))) (if (and (eq system-type 'windows-nt) (featurep 'xemacs)) (subst-char-in-string ?\\ ?/ file t)) (if (matlab-eei-breakpoint-exists-p file line) (matlab-eei-request-clear-breakpoint file line) (matlab-eei-request-set-breakpoint file line))) (error "You must save this buffer before attempting to set a breakpoint.")) ;; ) )(defun matlab-eei-clear-breakpoints () "Ask MATLAB to clear all breakpoints in the current buffer." (interactive) (matlab-run-in-matlab-mode-only (if matlab-eei-breakpoints-alist (matlab-eei-send-mcmd (format "request_clear_breakpoints") t))))(defun matlab-eei-event-clear-breakpoints () "Handle a clear breakpoints event from MATLAB." ;; (message "event clear breakpoints") (matlab-eei-breakpoints-clear) (setq matlab-eei-last-event "clear-breakpoints"))(defun matlab-eei-reset-breakpoints () (if (eq major-mode 'matlab-mode) (let* ((file (if (eq system-type 'windows-nt) (downcase (buffer-file-name)) (buffer-file-name))) (breakpoints (delq nil (mapcar (lambda (bp) (let ((xfile (car bp))) (if (string= xfile file) (matlab-eei-marker-line (cdr bp))))) matlab-eei-breakpoints-alist)))) (matlab-eei-clear-breakpoints) (if (and breakpoints (string= (matlab-eei-wait-for-event) "clear-breakpoints")) (progn (matlab-eei-send-mcmd (concat "reset_file " file)) (mapc (lambda (line) (matlab-eei-request-set-breakpoint file line)) breakpoints))))));; +------------------------------------+;; | Stop-if commands |;; +------------------------------------+(defvar matlab-eei-last-stop-if-command nil "Last stop-if command executed.")(defvar matlab-eei-stop-if-state '(("error" . nil) ("caught_error". nil) ("warning" . nil) ("nan_inf" . nil)) "")(make-variable-buffer-local 'matlab-eei-stop-if-state);; XEmacs compatibility.(if (not (fboundp 'assoc-ignore-representation)) (defalias 'assoc-ignore-representation 'assoc-ignore-case))(defun matlab-eei-get-stop-if-state (state-name) (cdr (assoc-ignore-representation state-name matlab-eei-stop-if-state)))(defun matlab-eei-set-stop-if-state (state-name state) (setcdr (assoc-ignore-representation state-name matlab-eei-stop-if-state) state))(defun matlab-eei-toggle-stop-if (condition) "Toggle stop-if state." (matlab-eei-send-mcmd (format "toggle_stop_if %s" condition)) (setq matlab-eei-last-stop-if-command condition))(defun matlab-eei-toggle-stop-if-error () "Toggle stop-if-error state for the M-file in the current buffer." (interactive) (matlab-run-in-matlab-mode-only (matlab-eei-toggle-stop-if "error")))(defun matlab-eei-toggle-stop-if-caught-error () "Toggle stop-if-caught-error state for the M-file in the current buffer." (interactive) (matlab-run-in-matlab-mode-only (matlab-eei-toggle-stop-if "caught_error")))(defun matlab-eei-toggle-stop-if-warning () "Toggle stop-if-warning state for the M-file in the current buffer." (interactive) (matlab-eei-toggle-stop-if "warning"))(defun matlab-eei-toggle-stop-if-nan-inf () "Toggle stop-if-nan-inf state for the M-file in the current buffer." (interactive) (matlab-eei-toggle-stop-if "nan_inf"))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -