Skip to main content
added 76 characters in body
Source Link

Thats what I'm using, not specific go any mode. Honors region if existing:

(defun just-one-empty-line (&optional beg end)
  "Delete consecutive empty lines, retain just one."

Works on region if active.
Accepts optional arguments BEG END to specify a region"
  (interactive "*")
  (let ((beg (cond (beg)
           ((region-active-p)
            (region-beginning))
           (t (point-min))))
    (end (cond (end (copy-marker end))
           ((region-active-p)
            (copy-marker (region-end)))
           (t (copy-marker (point-max))))))
    (save-excursion
      (save-restriction
        (narrow-to-region beg end)
        (goto-char beg)
        (while (not (eobp))
          (while (looking-at "^\\([ \t]*\n\\)[ \t]*$")
            (delete-region (match-beginning 1) (match-end 1)))
          (forward-line 1))
    (widen)))))

Thats what I'm using, not specific go any mode. Honors region if existing:

(defun just-one-empty-line (&optional beg end)
  "Delete consecutive empty lines, retain just one."
  (interactive "*")
  (let ((beg (cond (beg)
           ((region-active-p)
            (region-beginning))
           (t (point-min))))
    (end (cond (end (copy-marker end))
           ((region-active-p)
            (copy-marker (region-end)))
           (t (copy-marker (point-max))))))
    (save-excursion
      (save-restriction
        (narrow-to-region beg end)
        (goto-char beg)
        (while (not (eobp))
          (while (looking-at "^\\([ \t]*\n\\)[ \t]*$")
            (delete-region (match-beginning 1) (match-end 1)))
          (forward-line 1))
    (widen)))))
(defun just-one-empty-line (&optional beg end)
  "Delete consecutive empty lines, retain just one.

Works on region if active.
Accepts optional arguments BEG END to specify a region"
  (interactive "*")
  (let ((beg (cond (beg)
           ((region-active-p)
            (region-beginning))
           (t (point-min))))
    (end (cond (end (copy-marker end))
           ((region-active-p)
            (copy-marker (region-end)))
           (t (copy-marker (point-max))))))
    (save-excursion
      (save-restriction
        (narrow-to-region beg end)
        (goto-char beg)
        (while (not (eobp))
          (while (looking-at "^\\([ \t]*\n\\)[ \t]*$")
            (delete-region (match-beginning 1) (match-end 1)))
          (forward-line 1))
    (widen)))))
deleted 40 characters in body
Source Link

Thats what I'm using, not specific go any mode. Honors region if existing:

(defun just-one-empty-line (&optional beg end)
  "Delete consecutive empty lines, retain just one.

Delete trailing whitespace "
  (interactive "*")
  (let ((beg (cond (beg)
           ((region-active-p)
            (region-beginning))
           (t (point-min))))
    (end (cond (end (copy-marker end))
           ((region-active-p)
            (copy-marker (region-end)))
           (t (copy-marker (point-max))))))
    (save-excursion
      (save-restriction
        (narrow-to-region beg end)
        (goto-char beg)
        (while (not (eobp))
          (while (looking-at "^\\([ \t]*\n\\)[ \t]*$")
            (delete-region (match-beginning 1) (match-end 1)))
          (forward-line 1)))
      (widen)))))

Thats what I'm using, not specific go any mode. Honors region if existing:

(defun just-one-empty-line (&optional beg end)
  "Delete consecutive empty lines, retain just one.

Delete trailing whitespace "
  (interactive "*")
  (let ((beg (cond (beg)
           ((region-active-p)
            (region-beginning))
           (t (point-min))))
    (end (cond (end (copy-marker end))
           ((region-active-p)
            (copy-marker (region-end)))
           (t (copy-marker (point-max))))))
    (save-excursion
      (save-restriction
        (narrow-to-region beg end)
        (goto-char beg)
        (while (not (eobp))
          (while (looking-at "^\\([ \t]*\n\\)[ \t]*$")
            (delete-region (match-beginning 1) (match-end 1)))
          (forward-line 1)))
      (widen))))

Thats what I'm using, not specific go any mode. Honors region if existing:

(defun just-one-empty-line (&optional beg end)
  "Delete consecutive empty lines, retain just one."
  (interactive "*")
  (let ((beg (cond (beg)
           ((region-active-p)
            (region-beginning))
           (t (point-min))))
    (end (cond (end (copy-marker end))
           ((region-active-p)
            (copy-marker (region-end)))
           (t (copy-marker (point-max))))))
    (save-excursion
      (save-restriction
        (narrow-to-region beg end)
        (goto-char beg)
        (while (not (eobp))
          (while (looking-at "^\\([ \t]*\n\\)[ \t]*$")
            (delete-region (match-beginning 1) (match-end 1)))
          (forward-line 1))
    (widen)))))
Source Link

Thats what I'm using, not specific go any mode. Honors region if existing:

(defun just-one-empty-line (&optional beg end)
  "Delete consecutive empty lines, retain just one.

Delete trailing whitespace "
  (interactive "*")
  (let ((beg (cond (beg)
           ((region-active-p)
            (region-beginning))
           (t (point-min))))
    (end (cond (end (copy-marker end))
           ((region-active-p)
            (copy-marker (region-end)))
           (t (copy-marker (point-max))))))
    (save-excursion
      (save-restriction
        (narrow-to-region beg end)
        (goto-char beg)
        (while (not (eobp))
          (while (looking-at "^\\([ \t]*\n\\)[ \t]*$")
            (delete-region (match-beginning 1) (match-end 1)))
          (forward-line 1)))
      (widen))))