Skip to content

Commit

Permalink
[Fix #972] Add toggle for project read only mode.
Browse files Browse the repository at this point in the history
- it generates a `.dir-locals.el' file which controls the read-only behavior.
- logic is copied from ggtags.
  • Loading branch information
RenWenshan authored and bbatsov committed Sep 24, 2018
1 parent bf28c31 commit acbc72f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

* Add toggle for project read only mode: `projectile-toggle-project-read-only`.
* New interactive command `projectile-run-ielm`.
* Add [crystal](https://crystal-lang.org) project type.
* [#850](https://github.com/bbatsov/projectile/issues/850): Make it possible to prompt for a project, when you're not in a project, instead of raising an error. (see `projectile-require-project-root`).
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ it. Some of Projectile's features:
* visit project in dired
* run make in a project with a single key chord
* check for dirty repositories
* toggle read-only mode for the entire project

Here's a glimpse of Projectile in action:

Expand Down
15 changes: 15 additions & 0 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,20 @@ With a prefix arg INVALIDATE-CACHE invalidates the cache first."
(interactive "P")
(projectile--find-file invalidate-cache #'find-file-other-frame))

;;;###autoload
(defun projectile-toggle-project-read-only ()
"Toggle project read only"
(interactive)
(let ((inhibit-read-only t)
(val (not buffer-read-only))
(default-directory (projectile-project-root)))
(add-dir-local-variable nil 'buffer-read-only val)
(save-buffer)
(kill-buffer)
(when buffer-file-name
(read-only-mode (if val +1 -1))
(message "Projectile: project read-only-mode is %s" (if val "on" "off")))))


;;;; Sorting project files
(defun projectile-sort-files (files)
Expand Down Expand Up @@ -4025,6 +4039,7 @@ is chosen."
["Replace in project" projectile-replace]
["Multi-occur in project" projectile-multi-occur]
["Browse dirty projects" projectile-browse-dirty-projects]
["Toggle project wide read-only" projectile-toggle-project-read-only]
"--"
["Run shell" projectile-run-shell]
["Run eshell" projectile-run-eshell]
Expand Down

0 comments on commit acbc72f

Please sign in to comment.