clang-format-region assumes transient-mark-mode

Bug #1511978 reported by Jeff Abrahamson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
llvm-toolchain-3.7 (Ubuntu)
New
Undecided
Unassigned

Bug Description

From clang-format-3.5 to clang-format-3.6, the definition of clang-format-region changed in clang-format.el.

The old definition was this:

(defun clang-format-region ()
  "Use clang-format to format the currently active region."
  (interactive)
  (let ((beg (if mark-active
                 (region-beginning)
               (min (line-beginning-position) (1- (point-max)))))
        (end (if mark-active
                 (region-end)
               (line-end-position))))
    (clang-format beg end)))

The new definition begins thus:

(defun clang-format-region (char-start char-end &optional style)
  "Use clang-format to format the code between START and END according to STYLE.
If called interactively uses the region or the current statement if there
is no active region. If no style is given uses `clang-format-style'."
  (interactive
   (if (use-region-p)
       (list (region-beginning) (region-end))
     (list (point) (point))))

     ...

(It continues quite a bit longer.)

The call to use-region-p always returns false if transient-mark-mode is turned off, e.g. via (transient-mark-mode nil). This causes clang-format-region always to format the current line and never the selected region.

This is a fix, barring some further subtlety I've missed:

  (interactive
   (if mark-active
       (list (region-beginning) (region-end))
     (list (point) (point))))

ProblemType: Bug
DistroRelease: Ubuntu 15.10
Package: clang-format-3.7 1:3.7-2ubuntu1
ProcVersionSignature: Ubuntu 4.2.0-16.19-generic 4.2.3
Uname: Linux 4.2.0-16-generic x86_64
ApportVersion: 2.19.1-0ubuntu3
Architecture: amd64
CurrentDesktop: i3
Date: Sat Oct 31 17:34:38 2015
EcryptfsInUse: Yes
InstallationDate: Installed on 2015-10-23 (8 days ago)
InstallationMedia: Ubuntu 15.04 "Vivid Vervet" - Release amd64 (20150422)
SourcePackage: llvm-toolchain-3.7
UpgradeStatus: Upgraded to wily on 2015-10-23 (8 days ago)

Revision history for this message
Jeff Abrahamson (jeff-purple) wrote :
Revision history for this message
Jeff Abrahamson (jeff-purple) wrote :

I just found llvm.org/bugzilla, so I also filed the bug there:

https://llvm.org/bugs/show_bug.cgi?id=25365

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.