Skip to content

Commit 517f051

Browse files
committed
Various major mode improvements
Patch by Stefan Monnier
1 parent c9cfea0 commit 517f051

File tree

3 files changed

+93
-97
lines changed

3 files changed

+93
-97
lines changed

.gitignore

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
/.cask
1+
*.aux
2+
*.dvi
23
*.elc
34
*.log
4-
*.aux
55
*.pdf
6-
*.dvi
6+
*/#*#
77
*~
8+
.#*
89
/#*#
9-
*/#*#
10+
/*-autoloads.el
11+
/*-pkg.el
12+
/gpelcard.ps
1013
/hacks.el
11-
.#*
1214
/info-look.el
13-
/gpelcard.ps
1415
gnuplot-mode-*.tar.gz

gnuplot-gui.el

Lines changed: 78 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -828,15 +828,8 @@ This alist is formed at load time by appending together
828828
;;; user interface to the widget-y stuff
829829

830830
;;;###autoload
831-
(defun gnuplot-gui-mouse-set (event)
832-
"Use the mouse to begin setting options using a GUI interface.
833-
EVENT is a mouse event. Bound to \\[gnuplot-gui-mouse-set]
834-
Note that \"plot\", \"splot\", \"fit\", and \"cntrparam\" are not
835-
currently supported."
836-
(interactive "@e")
837-
(save-excursion
838-
(mouse-set-point event)
839-
(gnuplot-gui-set-options-and-insert)))
831+
(define-obsolete-function-alias 'gnuplot-gui-mouse-set
832+
#'gnuplot-gui-set-options-and-insert "2025")
840833

841834
(defun gnuplot-gui-get-frame-param (param)
842835
(cdr (assoc param gnuplot-gui-frame-parameters)))
@@ -845,86 +838,89 @@ currently supported."
845838
(setcdr (assoc param gnuplot-gui-frame-parameters) value))
846839

847840
;;;###autoload
848-
(defun gnuplot-gui-set-options-and-insert ()
841+
(defun gnuplot-gui-set-options-and-insert (&optional event)
849842
"Insert arguments using a GUI interface.
850843
Determine contents of current line and set up the appropriate GUI
851844
frame. Bound to \\[gnuplot-gui-set-options-and-insert]
852845
Note that \"cntrparam\" is not currently supported."
853846
(interactive)
854-
(let ((begin (gnuplot-point-at-beginning-of-command))
855-
(end (save-excursion (end-of-line) (point-marker)))
856-
(termin (concat "\\(,\\s-*" (regexp-quote "\\") "\\|;\\)"))
857-
(set nil) (term nil))
858-
(save-excursion
859-
;; there can be more then one command per line
860-
(if (re-search-forward termin end "to_limit")
861-
(progn (backward-char (length (match-string 1)))
862-
(setq end (point-marker))))
863-
(goto-char begin)
864-
(skip-syntax-forward "-" end)
865-
;; various constructions are recognized here. at the end of this
866-
;; cond, point should be just after the word whose arguments are
867-
;; to be set
868-
(cond ((looking-at "set\\s-+")
869-
(setq set t)
870-
(goto-char (match-end 0))
871-
(if (looking-at "\\sw+") (goto-char (match-end 0)))
872-
(when (string-match "^ter" (gnuplot-this-word)) ; terminal?
873-
(setq term t)
847+
(interactive (list last-nonmenu-event))
848+
(save-excursion
849+
(if event (mouse-set-point event))
850+
(let ((begin (gnuplot-point-at-beginning-of-command))
851+
(end (save-excursion (end-of-line) (point-marker)))
852+
(termin (concat "\\(,\\s-*" (regexp-quote "\\") "\\|;\\)"))
853+
(set nil) (term nil))
854+
(save-excursion
855+
;; there can be more then one command per line
856+
(if (re-search-forward termin end "to_limit")
857+
(progn (backward-char (length (match-string 1)))
858+
(setq end (point-marker))))
859+
(goto-char begin)
860+
(skip-syntax-forward "-" end)
861+
;; various constructions are recognized here. at the end of this
862+
;; cond, point should be just after the word whose arguments are
863+
;; to be set
864+
(cond ((looking-at "set\\s-+")
865+
(setq set t)
866+
(goto-char (match-end 0))
867+
(if (looking-at "\\sw+") (goto-char (match-end 0)))
868+
(when (string-match "^ter" (gnuplot-this-word)) ; terminal?
869+
(setq term t)
870+
(forward-word 1))
871+
(when (string-match "^\\(da\\|fu\\)" (gnuplot-this-word))
872+
(unless (looking-at "\\s-+st")
873+
(insert " style") (forward-word 1))
874+
(forward-word 1)))
875+
((looking-at (concat "\\(cd\\|ca\\|lo\\|pa\\|pr\\|sa\\|u\\)"
876+
"\\w*"
877+
"[\\s-\\']"))
874878
(forward-word 1))
875-
(when (string-match "^\\(da\\|fu\\)" (gnuplot-this-word))
876-
(unless (looking-at "\\s-+st")
877-
(insert " style") (forward-word 1))
878-
(forward-word 1)))
879-
((looking-at (concat "\\(cd\\|ca\\|lo\\|pa\\|pr\\|sa\\|u\\)"
880-
"\\w*"
881-
"[\\s-\\']"))
882-
(forward-word 1))
883-
;;(goto-char (match-end 0)))
884-
(t
885-
(forward-word 1)))
886-
(if (> (point) end) (goto-char end))
887-
(let* ((w (gnuplot-this-word))
888-
(wd (try-completion w gnuplot-gui-all-types))
889-
(word "") wrd list)
890-
(cond ((equal wd t) (setq word w))
891-
((equal wd nil) (setq word w))
892-
((assoc wd gnuplot-gui-all-types) (setq word wd))
893-
(t (setq wd nil)))
894-
(cond ((equal (string-match "^\\s-*$" w) 0)
895-
(message "Blank line"))
896-
((and wd (stringp word))
897-
(gnuplot-gui-correct-command word set term begin)
898-
(setq gnuplot-gui-alist nil
899-
gnuplot-gui-current-string
900-
(buffer-substring-no-properties (point) end))
901-
(gnuplot-gui-set-alist word gnuplot-gui-current-string)
902-
(let* ((old-height (gnuplot-gui-get-frame-param 'height))
903-
(old-top (gnuplot-gui-get-frame-param 'top)))
904-
(when (or
905-
(and (equal gnuplot-gui-plot-splot-fit-style 'complete)
906-
(cl-member word '("plot" "splot" "fit")
907-
:test 'string=))
908-
(equal word "test"))
909-
(gnuplot-gui-set-frame-param 'height 32)
910-
(gnuplot-gui-set-frame-param 'top 50))
911-
(gnuplot-gui-prompt-for-frame word)
912-
(when (or
913-
(and (equal gnuplot-gui-plot-splot-fit-style 'complete)
914-
(cl-member word '("plot" "splot" "fit")
915-
:test 'string=))
916-
(equal word "test"))
917-
(gnuplot-gui-set-frame-param 'height old-height)
918-
(gnuplot-gui-set-frame-param 'top old-top)) ))
919-
((setq wrd (car (all-completions w '(("cntrparam")))))
920-
(message
921-
"Setting arguments for %S is currently unsuported in gnuplot-mode"
922-
wrd))
923-
((setq list (all-completions w gnuplot-gui-all-types))
924-
(message "%S could be one of %S" w list))
879+
;;(goto-char (match-end 0)))
925880
(t
926-
(message
927-
"%S is not a gnuplot command which takes options" w)))) )))
881+
(forward-word 1)))
882+
(if (> (point) end) (goto-char end))
883+
(let* ((w (gnuplot-this-word))
884+
(wd (try-completion w gnuplot-gui-all-types))
885+
(word "") wrd list)
886+
(cond ((equal wd t) (setq word w))
887+
((equal wd nil) (setq word w))
888+
((assoc wd gnuplot-gui-all-types) (setq word wd))
889+
(t (setq wd nil)))
890+
(cond ((equal (string-match "^\\s-*$" w) 0)
891+
(message "Blank line"))
892+
((and wd (stringp word))
893+
(gnuplot-gui-correct-command word set term begin)
894+
(setq gnuplot-gui-alist nil
895+
gnuplot-gui-current-string
896+
(buffer-substring-no-properties (point) end))
897+
(gnuplot-gui-set-alist word gnuplot-gui-current-string)
898+
(let* ((old-height (gnuplot-gui-get-frame-param 'height))
899+
(old-top (gnuplot-gui-get-frame-param 'top)))
900+
(when (or
901+
(and (equal gnuplot-gui-plot-splot-fit-style 'complete)
902+
(cl-member word '("plot" "splot" "fit")
903+
:test 'string=))
904+
(equal word "test"))
905+
(gnuplot-gui-set-frame-param 'height 32)
906+
(gnuplot-gui-set-frame-param 'top 50))
907+
(gnuplot-gui-prompt-for-frame word)
908+
(when (or
909+
(and (equal gnuplot-gui-plot-splot-fit-style 'complete)
910+
(cl-member word '("plot" "splot" "fit")
911+
:test 'string=))
912+
(equal word "test"))
913+
(gnuplot-gui-set-frame-param 'height old-height)
914+
(gnuplot-gui-set-frame-param 'top old-top)) ))
915+
((setq wrd (car (all-completions w '(("cntrparam")))))
916+
(message
917+
"Setting arguments for %S is currently unsuported in gnuplot-mode"
918+
wrd))
919+
((setq list (all-completions w gnuplot-gui-all-types))
920+
(message "%S could be one of %S" w list))
921+
(t
922+
(message
923+
"%S is not a gnuplot command which takes options" w)))) ))))
928924

929925
;;;###autoload
930926
(defun gnuplot-gui-toggle-popup ()

gnuplot.el

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,11 @@ suggestions."
282282
(set sym value)
283283
(cond
284284
(value
285-
(add-hook 'gnuplot-mode-hook 'gnuplot-context-sensitive-mode nil nil)
286-
(add-hook 'gnuplot-comint-mode-hook 'gnuplot-context-sensitive-mode nil nil))
285+
(add-hook 'gnuplot-mode-hook #'gnuplot-context-sensitive-mode nil nil)
286+
(add-hook 'gnuplot-comint-mode-hook #'gnuplot-context-sensitive-mode nil nil))
287287
(t
288-
(remove-hook 'gnuplot-mode-hook 'gnuplot-context-sensitive-mode)
289-
(remove-hook 'gnuplot-comint-mode-hook 'gnuplot-context-sensitive-mode)))
288+
(remove-hook 'gnuplot-mode-hook #'gnuplot-context-sensitive-mode)
289+
(remove-hook 'gnuplot-comint-mode-hook #'gnuplot-context-sensitive-mode)))
290290
(dolist (buffer (buffer-list))
291291
(with-current-buffer buffer
292292
(when (and (derived-mode-p 'gnuplot-mode 'gnuplot-comint-mode)
@@ -376,7 +376,7 @@ non-nil."
376376
(let ((map (make-sparse-keymap)))
377377
(define-key map "\C-c\C-b" #'gnuplot-send-buffer-to-gnuplot)
378378
(define-key map "\C-c\C-c" #'comment-region) ; <RF>
379-
(define-key map "\C-c\C-o" 'gnuplot-gui-set-options-and-insert)
379+
(define-key map "\C-c\C-o" #'gnuplot-gui-set-options-and-insert)
380380
(define-key map "\C-c\C-e" #'gnuplot-show-gnuplot-buffer)
381381
(define-key map "\C-c\C-f" #'gnuplot-send-file-to-gnuplot)
382382
(define-key map "\C-c\C-d" #'gnuplot-info-lookup-symbol)
@@ -394,7 +394,7 @@ non-nil."
394394
(define-key map (kbd "}") #'gnuplot-electric-insert)
395395
(define-key map "\M-\r" #'completion-at-point)
396396
(define-key map "\M-\t" #'completion-at-point)
397-
(define-key map [S-mouse-2] 'gnuplot-gui-mouse-set)
397+
(define-key map [S-mouse-2] #'gnuplot-gui-set-options-and-insert)
398398

399399
map))
400400

@@ -1384,7 +1384,7 @@ buffer."
13841384
(let ((gnuplot-cmd (list #'make-comint gnuplot-process-name gnuplot-program)))
13851385
(when gnuplot-program-args
13861386
(setq gnuplot-cmd (append gnuplot-cmd '(nil) (split-string gnuplot-program-args))))
1387-
(setq gnuplot-buffer (eval gnuplot-cmd)
1387+
(setq gnuplot-buffer (eval gnuplot-cmd t)
13881388
gnuplot-process (get-buffer-process gnuplot-buffer)))
13891389
(set-process-query-on-exit-flag gnuplot-process nil)
13901390
(with-current-buffer gnuplot-buffer
@@ -1582,7 +1582,7 @@ then removes itself from `comint-preoutput-filter-functions'."
15821582
(when (looking-back gnuplot-prompt-regexp (point-min))
15831583
(with-current-buffer gnuplot-buffer
15841584
(remove-hook 'comint-preoutput-filter-functions
1585-
'gnuplot-discard-output t))))
1585+
#'gnuplot-discard-output t))))
15861586
"")
15871587

15881588

@@ -2049,7 +2049,6 @@ a list:
20492049

20502050
(setq gnuplot-comint-recent-buffer (current-buffer))
20512051
(setq-local comint-process-echoes gnuplot-echo-command-line-flag)
2052-
(run-hooks 'gnuplot-mode-hook)
20532052
(gnuplot-setup-menubar))
20542053

20552054
;;;###autoload

0 commit comments

Comments
 (0)