File watchers

File watchers, in general, are tools that allow us to monitor the changes taking place in a given file and apply a specific action to the file when a change does take place. As an example, let's say even though PyCharm is a great IDE, there are files where we only want to use Atom (the text editor) to write code, and YAML files are one of them. So anytime there is a change taking place in a YAML file within PyCharm, we would like to open it in Atom instead.

To set up such a file watcher, we will go through the following:

  1. From the settings, go to Tools | File Watchers. This will take you to the main window to manage file watchers.
  2. Click on the + button in the top-right corner of the window to add in a new file watcher and choose to create a new custom file-watcher template:

Creating a file-watcher template
  1. Now, enter the following information in the new pop-up window to specify our file watcher:

Creating a file watcher in PyCharm
  1. The name for the file watcher can be anything you like. The File type prompt specifies the file extension that will be monitored by this file watcher (in our case, it is YAML files). The Scope prompt, on the other hand, defines where this file watcher is to take effect; here, I'm specifying it to be in all places in PyCharm.
  2. The Program prompt should be the path to the program that we'd like to use in the file watcher. Here, I'm specifying the path to the executable for Atom. In the Arguments prompt, we use a macro ($FileName$) to dynamically specify the name of a given YAML file.
To open a file in Atom, we run the atom [file name] command, so that's why we specify the command as previously. You need to customize the Program and Arguments prompts so that when combined, the command can successfully achieve your goal.
  1. Finalize your customization by clicking OK.

To see if this file watcher is working as intended, simply create a new YAML file within PyCharm and attempt to edit it. You will see that the file will be opened in Atom as well. As you can imagine, this feature is quite useful for automating tasks that run every time a specific type of file is edited. For example, common files that you can apply file watchers to are LESS files (which can be compiled into CSS) or CoffeeScript files (which can be converted into JavaScript).

This discussion also concludes the miscellaneous topics in PyCharm that I wanted to cover. In the next section, we will walk through the other topics that we have looked at throughout this book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.17.20