[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gnuplot 00cb492 010/184: Improved continuation line handli
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gnuplot 00cb492 010/184: Improved continuation line handling by indentation & gnuplot-send-line-* |
Date: |
Sun, 29 Aug 2021 11:03:05 -0400 (EDT) |
branch: elpa/gnuplot
commit 00cb492a79cdef5bed8b900788e4ba33f67b3a69
Author: Jonathan Oddie <j.j.oddie@gmail.com>
Commit: Jonathan Oddie <j.j.oddie@gmail.com>
Improved continuation line handling by indentation & gnuplot-send-line-*
- New defun gnuplot-continuation-line-p: check whether current line is
a continuation line
- New defun gnuplot-back-to-continuation-beginning: move point to the
beginning of a continued command, or beginning of line if not on a
continuation line
- Mostly-new gnuplot-indent-line fixes bug with indentation of line
after a continuation, works for continued commands other than
[s]plot
- gnuplot-send-line-to-gnuplot and gnuplot-send-line-and-forward work
from anywhere inside a continued command
---
gnuplot.el | 98 +++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 58 insertions(+), 40 deletions(-)
diff --git a/gnuplot.el b/gnuplot.el
index 5162a83..6178b78 100644
--- a/gnuplot.el
+++ b/gnuplot.el
@@ -1700,19 +1700,17 @@ Respects continuation lines.
This sets `gnuplot-recently-sent' to 'line."
(interactive)
(cond ((equal major-mode 'gnuplot-mode)
- (let ((start (save-excursion (beginning-of-line) (point-marker)))
- end
- ;(end (save-excursion (beginning-of-line 2) (point-marker)))
- )
- (save-excursion
- (goto-char start)
+ (let (start end)
+ (save-excursion
+ ;; go to start of continued command, or beginning of line
+ ;; if this is not a continuation of a previous line <JJO>
+ (gnuplot-back-to-continuation-beginning)
+ (setq start (point))
(end-of-line)
- (backward-char 1)
- (while (looking-at "\\\\") ; go to end of last continuation line
- (end-of-line 2)
- (backward-char 1))
+ (while (looking-back "\\\\") ; go to end of last
continuation line
+ (end-of-line 2))
(beginning-of-line 2)
- (setq end (point-marker)))
+ (setq end (point)))
(if (not (string-match "\\`\\s-*\\'"
(buffer-substring-no-properties start end)))
(gnuplot-send-region-to-gnuplot start end 'line))
@@ -2039,39 +2037,59 @@ Bound to \\[gnuplot-insert-filename]"
default-directory)
gnuplot-quote-character) )
-;; is this more complicated than it need be ...?
-;; this doesn't quite do plot lists correctly:
-;; plot sin(x),\
-;; cos(x) # ok
-;; set auto # not ok, should be under "p" (but does it matter?)
-
+;;
+;; Adjust indentation for the line containing point
(defun gnuplot-indent-line ()
"Set indentation in gnuplot buffer.
For most lines, set indentation to previous level of indentation.
-Attempt to add additional indentation for continued plot and splot
-lines."
+Add additional indentation for continuation lines."
(interactive)
- (let ((indent 0))
- (save-excursion
- (save-excursion
- (end-of-line 0)
- (if (bobp) ()
- (re-search-backward "^[ \t]*." (point-min) "to_limit")
- (back-to-indentation)
- (setq indent (current-column))
- (if (looking-at "s?pl\\(o?\\|\\(ot\\)?\\)[ \t]+.?")
- (let ((plus (1- (length (match-string 0)))))
- (end-of-line)
- (backward-char 1)
- (if (looking-at (regexp-quote "\\"))
- (setq indent (+ plus indent)))))))
- (if (= (current-indentation) indent)
- ()
- (beginning-of-line)
- (delete-horizontal-space)
- (insert (make-string indent ? ))))
- (if (looking-at "[ \t]+$")
- (end-of-line))))
+ (let (indent)
+ (save-excursion
+ (if (gnuplot-continuation-line-p)
+ ;; This is a continuation line. Indent to the same level as
+ ;; the second word on the line beginning this command (i.e.,
+ ;; the first non-whitespace character after whitespace)
+ (progn
+ (gnuplot-back-to-continuation-beginning)
+ (back-to-indentation)
+ (re-search-forward "[^[:space:]]+[[:space:]]+" (point-at-eol)
'end-at-limit)
+ (setq indent (- (point) (point-at-bol))))
+
+ ;; Not a continuation line; go back to the first non-blank,
+ ;; non-continuation line and indent to the same level
+ (beginning-of-line 0)
+ (while (and (not (bobp))
+ (or (gnuplot-continuation-line-p)
+ (looking-at "[[:space:]]*$")))
+ (beginning-of-line 0))
+ (if (bobp)
+ (setq indent 0)
+ (setq indent (current-indentation)))))
+
+ ;; Set indentation
+ (save-excursion
+ (indent-line-to indent))
+
+ (let ((point-at-indent (+ (point-at-bol) indent)))
+ (when (< (point) point-at-indent) (goto-char point-at-indent)))))
+
+;; Check if line containing point is a continuation
+(defun gnuplot-continuation-line-p ()
+ "Return t if the line containing point is a continuation line"
+ (save-excursion
+ (end-of-line 0)
+ (looking-back "\\\\")))
+
+;; Move point back to start of continued command
+(defun gnuplot-back-to-continuation-beginning ()
+ "Move point to the beginning of the first line which this line is
+a continuation of.
+If this is not a continuation line, move point to beginning of line."
+ (interactive)
+ (beginning-of-line)
+ (while (gnuplot-continuation-line-p)
+ (beginning-of-line 0)))
;; FWIW, here are all the options which can be negated:
;; (insert (format "%s"
- [nongnu] elpa/gnuplot b6c56b7 020/184: Modified .gitignore, (continued)
- [nongnu] elpa/gnuplot b6c56b7 020/184: Modified .gitignore, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 171bbea 046/184: Numerous grammar tweaks. Implement `many1' repetition (regex `+')., ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot fca0deb 030/184: make-local-hook causes erros with GNU Emacs 24, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot bef60ba 019/184: Create a gnuplot-comint buffer in gnuplot-show-gnuplot-buffer if none exists., ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot c3259fb 039/184: Merge branch 'context' of github.com:bruceravel/gnuplot-mode into context, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 674a21d 040/184: Merge remote-tracking branch 'origin/devel' into devel, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot de13740 038/184: Added experimental context-sensitive completion and help code., ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 23f2060 032/184: Merge branch 'master' into devel, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 78d691b 003/184: Updated readme, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot e679a59 002/184: import everything, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 00cb492 010/184: Improved continuation line handling by indentation & gnuplot-send-line-*,
ELPA Syncer <=
- [nongnu] elpa/gnuplot a375477 031/184: Merge pull request #7 from mcraveiro/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 566e92f 027/184: Fixed a dumb bug in gnuplot-indent-line., ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot aba40f1 034/184: Document the change to `gnuplot-make-regexp', ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 72ccda3 017/184: Improved syntax parsing and highlighting, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 2387f12 016/184: Restored some XEmacs compatibility that I broke., ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot df865fc 013/184: Slight change to font-lock regexps, and use buffer-local variables, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 0faec4f 022/184: Check that gnuplot-process is not nil in gnuplot-close-down, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 57fd4a2 036/184: Attempt to fix issue #9, void-function gnuplot-start-comint-function, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot ca241a7 035/184: Merge remote-tracking branch 'origin/devel' into devel, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 7f29578 023/184: Minor improvements to movement-by-command functions, ELPA Syncer, 2021/08/29