Tag: emacs

  • programmatically install packages with emacs27 and above

    In the emacs community, this is often a frequent question how can you install packages, while M-x package-list and M-x package-install can be a lot of help, you do not want to do it every time you install emacs, a better way is to add your packages in init.el and let emacs programmatically download and install you most frequent used packages.

    Here is a quick step on how you can achieve this with your init.el file is to use package-refresh-contents, but this will only work with the packages already present in your emacs library, basically this will just refresh those packages to their latest version and that’s it.

    But how we can download packages which we need on a machine where we are setting emacs for the first time.

    The first step is to add your elpa and melpa repositories, I do this by adding the following in my inti.el file, this add the repos and initialize them

    ;; load emacs package repostiroies.<br>(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")<br>("marmalade" . "http://marmalade-repo.org/packages/")<br>("melpa" . "https://melpa.org/packages/")<br>("elpy" . "https://jorgenschaefer.github.io/packages/")))

    next, we initialize the package list code

    (package-initialize)
    (when (not package-archive-contents)
      (package-refresh-contents))
    

    next, I have created my own variable for my packages where I keep all my packages

    (defvar myPackages
      '(better-defaults
        ein
        elpy
        flycheck
        material-theme
        py-autopep8))

    and here the variable is called using package-install function already initialized with package-initialize command

    (mapc #'(lambda (package)
        (unless (package-installed-p package)
          (package-install package)))
          myPackages)

    This provides me with the ability to avoid touching my main package installation code every time and I need to simply update my package list variable, which does package-install in my next emacs run, or I just call eval-buffer and reread the init.el file.

  • Emacs – 30 Days Challenge

    Emacs – 30 Days Challenge

    This is my learning journey to learn emacs in the next 30 Days. I am going to share my learning on this blog page.
     
    Below is the outline of the content I am planning to touch upon during my 30 Days challenge.
    • Day 1: Welcome to emacs
    • Day 2: Help in Emacs

    “ Emacs is the extensible, customisable, self-documenting real-time display editor.”

    – Emacs Manual

    Emacs can control OS subprocesses, helps in indenting programs, perform functions on many files at once and act as a simple text editor.

    Emacs can be easily altered to behave in a certain way as you want and is highly customizable. Advanced users of emacs can go beyond simple customization and can create entirely new commands. These new commands are simple programs written in LISP and are also known as macros.

    Downloading

    Most of my writing I do mainly with a Mac Pro, so I downloaded the mac version of emacs, there are multiple emacs variants present, but I preferred vanilla emacsformacosx, which gives me enough room for customization as per my needs.

    The commands and helps mentioned in my blogs will work on all the emacs variants regardless of your choice of OS.

    I downloaded MAC OS X from http://emacsformacosx.com/.

    In a lot of blogs and on #emacs IRC channel, people recommend using vanilla emacs while learning emacs. Customized variants of emacs come with pre-built commands which limits the learning curve.
    It is much easier to download and install emacs on Mac OS X. Download the latest version of emacs. Double click on the installer and follow the instructions.

    For Windows and Linux you can download GNU Emacs releases from a nearby GNU mirror; or if automatic redirection does not work see the list of GNU mirrors, or use the main GNU ftp server.

    GNU Emacs development is hosted on savannah.gnu.org.

    Working with emacs

    • Starting the editor: once installed start emacs from Launchpad -> emacs, clicking on which took me to the editor in its full glory, with a nice welcome message with a link to the manual and the beginner emacs tutorials to get a start working with emacs and to quickly get help in emacs “C-h (Hold down Ctrl and Press h)

    emacs welcome screen
    When starting the emacs editor for the first time, the emacs welcome screen

    Few things to note and which are global to emacs.

    We are following the standard emacs documentation while learning emacs to do our tasks, for the rest of the blog and my future emacs/non-emacs related posts, I am going to use Control Key as ‘C’. Alt or Esc Key as ‘M’ or referred in the document as meta key. Shift as ‘S’.

    Control keys are the “CTRL” keys on your keyoboard, usually on the bottom-left and bottom-right(near the shift key) keys.

    Meta Keys are “ALT” or “ESC” key on your keyboard.

    Shift Keys are the “SHIFT” keys on the left(below caps lock key) and right (below enter key) on your keyboard.

    Moving around

    Arrow keys on the keyboard can help you navigate around emacs text, it works similar to other text editors. Still, it is important that you learn the CTRL and Meta(ALT/ESC) key bindings to navigate around your document/code-block.
    Examples of some common key-bindings which you will be using almost daily while working within emacs.
    Keys Movement
    C-v View next screen also as Page Up.
    M-v Move Backward one screen or Page Down.
    C-l redisplay the text with the cursor at the center of the screen.
    C-p Previous line or up arrow key.
    C-b back one character or left arrow key.
    C-f forward one character or right arrow key.
    C-n Next line or down arrow key.
    M-f Move one forward one word.
    M-b Move back one word.
    C-a Move to the beginning of the line.
    C-e Move to the end of the line.
    M-a Move to the beginning of the sentence.
    M-e Move to the end of the sentence.
    C-u to specify a repeat count. C-v and M-v are exceptions as they won’t move pages but instead will scroll to that many lines forward/backward
    C-g Kill the running command in minibuffer, or in case emacs stop responding.
    C-d Delete the next character after the cursor.
    DEL delete the character just before the cursor.
    Insert text insertion is as simple as typing it. you can use the C-u to insert text as well. for eg. C-u 10 – will insert 10 hyphens “-———”.
    M-</td> Kill the word before the cursor.
    M-d Kill the word after the cursor
    C-k Kill from the cursor position to the end of the line.
    M-k Kill to the end of the current sentence.
    C-</td> Set the mark, move around with the above keys to highlight the text.
    C-y Yank the file back.
    C-x C-f Find the file, can be used for creating a file or opening an existing file.
    C-x C-s Save the file, when you made some changes to the file and want to write the same to disk or save it.
    C-x s Save some buffers.
    C-x C-b List all the opened Buffers.
    C-x b Switch buffer around.
    C-x C-c Quit Emacs.
    These are some of the common keys for moving around while in emacs.
     
    In the beginning, it seems hard to remember these key bindings for moving around within emacs. As we go along and with practice, these key sequences will become part of daily use.
     
    As a beginner, the above chart looks intimidating, and using arrow keys is easier to move around, but we should practice adopting and try use Ctrl and Meta sequences wherever possible and become more proficient using them, in the long run, you will observe it is much easier to work with key sequences.
  • How to get help for Emacs

    How to get help for Emacs

    This post is part of my 30 Days emacs challenge

    With years working with a variety of editors(vim, pico, nano, emacs). I find emacs to be capable of tasks such as text-editing, IDE, IRC, Organizer, mail client, source code management; yes emacs can do all these things with ease and is good at doing all of these.

    I do not mean that other editors can’t do the things which emacs can, and really do not want to start an editor war over it, but the ease of doing things with emacs outweighs other editors.

    The text editor comes with full-fledged documentation for common tasks for almost everything you want to do on your PC. 

    Before we go on exploring other topics for emacs, let’s start with knowing the emacs help system better.

    emacs is an acronym for Editor MACros has macros been written within emacs for some common tasks and is available to anyone for writing macros for their repetitive tasks.  In my later blogs, we will pick more on macros.

    Just for an overview, in emacs, A keyboard macro is a sequence of keys. For example, if you want to type C-n M-d C-d forty times, you can define a keyboard macro to do C-n M-d C-d, and then executing it 39 more times. 

    Emacs has the most robust help system available and all its help is available through a prefix of ‘C-h’ or F1. To know more on what is ‘C-‘ and ‘M-‘ in emacs please refer to my 30 Days emacs challenge

    Quickly find help in Emacs with its online documentation.

    • The Landing page, if you are very new: C – h t (opens the Emacs Tutorial)
    • Help on any function: F1 f function name
    • Help on summary of help commands: F1 F1
    • Help for topics: C – h a
    • Help on the topic in the Emacs index shows the first result: C – h i d m emacs <RET> i topic <RET>
    • Similar, but searched the text, instead of just indexes: C – h i d m emacs <RET> s topic <RET>
    • Emacs FAQ: C – h C -f
    • Available Emacs packages: C – h p

    Every emacs command has a name that is used as mapped with key bindings. Most emacs commands don’t have key bindings so the only way to learn them is to use them as commands, by emacs convention all the commands will consist of one or more words separated by ‘-‘. For eg. auto-fill-mode or manual-entry. So to enter a command, type M-x “enter the name of the command” RET (to execute), In case you change your mind to cancel the command pressing C-g (to cancel) will immediately cancel the command and put you into the main buffer. 

    Similarly apropos are the commands which may answer certain questions as “what are the commands for working with files?”. specifying an apropos pattern such as a word, a list of words, or regular expressions, each apropos command display a list of item that matches the pattern in a separate window.

    CommandsDescription
    C-h a *TOPICS*Searched for the command whose name matches the arguments
    C-h i d m *emacs* RET i *TOPIC* RETThis searches for the topic in the indices of the online emacs manual, and prints the first match
     ‘,’ to jump to the subsequent matches, we can also use regexes here.
    C-h i d m *emacs* RET s *TOPIC* RETSame as above, but instead of just searching the indices, it searches the manual too.
    C-h C-fDisplays the FAQ.
    C-h pDisplay all the emacs package based on the keywords.
    C-h bDisplay all active key bindings
    C-h c *key*show the name of the command it runs. (describe-key-briefly)
    C-h d *TOPICS* RETDisplay command and variables whose documentation matches the topic. (aprops-documentation)
    C-h eDisplay **Message** Buffer
    C-h f *function* RETDisplay documentation on the LISP function (describe-function)
    C-h hDisplay the ‘HELLO’ file
    C-h iRun info, the GNU documentation browser, the complete emacs document is available online in info
    C-h keyDisplay the name and the documentation of the command that the key runs. (describe-key)
    C-h lDescription of last 300 keystrokes. (view-lossage)
    C-h fDisplay documentation of the current major mode. (describe-mode)
    C-h nDisplay news of recent changes. (view-emacs-news)
    C-h pfind packages by topic keyword. ((finder-by-keyword)
    C-h rDisplay the emacs manual. (info-emacs-manual)
    C-h sDisplay the current contents of the syntax table, with an explanation of what they mean
     (describe-syntax)
    C-h tenter the emacs interactive tutorial. (help-with-tutorial)
    C-h v *var* RETDisplay the doc for the LISP variable var. (describe-variable).
    C-h w *command* RETShow which keys run the command named command. (where-is)
    C-h C *coding* RETDescribe the coding system. (describe-coding-system)
    C-h C RETDescribe the coding system currently in use.
    C-h F *COMMAND* RETEnter Info and go to node that documents emacs command *command*. (info-goto-emacs-command-node)
    C-h I *method* RETDescribe the input *method*. (describe-input-method)
    C-h K *key*go to the key-sequence document in Info. (Infp-goto-emacs-key-command-node)
    C-h L *Language-env* RETDisplay info on the character set, coding system, and input methods. (describe-language-environment)
    C-h S *Symbol* RETDisplay the info on the symbol *symbol* based on the programming mode you are using (info-lookup-symbol)
    C-h .Display message for the special text area. (display-local-help)
    **Apropos** 
    C-h a *pattern* RETSearch for a command whose names match the pattern.
    M-x apropos RET *pattern* RETSearch for functions(both interactive and non-interactive) and variables whose name matches the *pattern*
    M-x apropos-variable RET *pattern* RETSearch for user-option variables matching the *pattern*.
    M-x apropos-value RET *pattern* RETsearch for function whose definition match *pattern* and variable whose value matches *pattern*
    C-h d *pattern* RETsearch for function and variable whose documentation string matches *pattern*
    **Emacs help files** 
    C-h C-cDescribe the emacs copying condition. rules for copying and redistributing emacs. (describe-copying)
    C-h C-dDebugging in emacs. (view-emacs-debugging)
    C-h gDisplay general information about GNU Project. (describe-gnu-project)
    C-h C-mHow to order printed copies. (view-order-manual)
    C-h C-nTo see the emacs news and listing of new features. (view-emacs-news)
    C-h C-oHow to get the new version. (describe-distribution)
    C-h C-pTells us about the known emacs problems. (view-emacs-problems)
    C-h C-tDisplay the emacs TODO list or things that need to be done. (view-emacs-todo)
    C-h C-wDescribe warranty. (describe-no-warranty)

    Commands work in Help mode 

    SPCScroll forward
    DELScroll backward
    TABMove point forward to next cross reference
    S-TABMove point backward to the previous reference
    RETFollow a cross reference point.
    C-c C-cShow all documents of the symbol at the point.

    I am convinced the emacs has got the most extensive documentation an editor could ever have, the above table tries to cover as many things as possible but I am pretty sure, I would have definitely missed things, like this that once on IRC I had been suggested some lisp code to quickly take me to the help page and I missed it. Well, on many modern keyboards F1 works well for help.

    I tried to cover as much help command as possible in today’s blog posts which will come in handy for daily usage. Will soon be publishing text editing with emacs. 

  • Hello, World from Org2Blog/wp-new-entry.

    This is my test blog post from Aquamacs.

    Well, i am just going to write a brief about how I made this post work.

    First of all, let me point you to this wonderful link, which list down the way to make emacs and org-mode work with wodpress and make this post possible.

    So, here what i did.

    I had this melpa and elpa repostiory already configured. so quickly did M-x package-install return; org2blog return
    some quick configuration changes in my .emacs file to incorporate the org2blog settings and wordpress cofiguration.
    (setq org2blog/wp-blog-alist
        '(("pablumfication"
           :url "http://username.wordpress.com/xmlrpc.php"
           :username "admin")))
    Now, we just need to login to our wordpress blog, M-x org2blog/wp-login return
    and start writing post with M-x org2blog/wp-new-entry return
    Happy blogging C-c p return.
  • Things I learnt to do with emacs.

    1. To tweet.
    2. To Blog.
    3. As a personal todo and task taker using org-mode.
    4. As an IRC Client.
    5. As a text based web browser.
    6. As an MUA(Mail User Agent).
    7. As a shell terminal.
    8. As a file manager.
    9. Using github as version control.
    10. Last but not the least as an editor, to code and do things amazingly. Take the tour.

  • Famous emacs users(who are not famous for using emacs)

    Was using emacs from quite sometime as my primary editor for two reasons one as to learn more about emacs as an editor and two a wonderful platform to do many things. And during my learning curve came across this page created by “Wenshan” and this list is just amazing.

    mơ bắt cá 1

    But of course using emacs will not end up making me a great programmer, so these relatively known people and me might only thing in common is we used emacs at some point of time(or may have kept using).

  • emacs todo mode

    This tutorial has been posted by Logan Lee on the Usenet (http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/6d55768f621067c6/cec507b4c628b776?pli=1):

     (1) To enter todo major mode, M-x todo-mode.
     (2) Let's jump to the default Todo category. Press 'j' then select 'Todo'.
     (3) Let's insert a dummy task. Press 'i' then enter description then category that it belongs to. In this case, there is only one category (ie. Todo) so enter 'Todo' as its category.
     (4) Let's insert another dummy task in order to demonstrate raising or lowering priority of a task or filing a task once it's done. Do this by pressing 'i' again and following the rest of step 3.
     (5) Now, try pressing 'r' to move the task at cursor up by one line or 'l' to lower it by one line. The line position of a task represents its respective priority.
     (6) Now, try pressing 'f' at a task to file it. Filing a task means you add it to a file called '.todo-done' located at your home directory. You will see on your screen that the filed task has disappeared from view.
     (7) Lastly, let's try adding a new category. 'M-x todo-add-category'. First, you will be directed to the source of '.todo-do' file. Don't panic because of unknown syntax shown to your screen. Proceed to step 8 to learn  more about the syntax of .todo-do file.
     (8) The format of .todo-do file:
    
    
     ;; This specifies that "Todo" and "New Category That You Have Added" are
     ;;+categories of todo-mode.
     -*- mode: todo; todo-categories: ("Todo","New Category That You Have Added"); -*-
     */* --------------------------------------------------------------------------- 
     ;; Lists tasks under Todo
     */* --- Todo
     */* 2007-01-02 19:12 Dummy Task2        ;; These are dummy tasks from steps 3,4.
     */* 2007-01-02 19 11 Dummy Task1        ;;+Task2 is higher priority than Task1.
     --- End
     ;; Lists tasks under New Category That You Have Added
     */* --- New Category That You Have Added
     ;; As you can see there are no tasks belonging to "New Category That You Have Added" ;)
     --- End
     (9) There are other commands and associated abbreviations which can be found in Todo item at menu bar.