Uploads from Xah Lee

Watch and track your favorite playlist.

Curated by: Xah Lee (847 videos)


Currently Playing: Ep712 Emacs Lisp, Move File to Parent Dir. car cdr cons, Supreme Functional Programing No Variable

Video Summary (Generated by AI, Editedby Human.) In this video, Xah Lee codes in Emacs Lisp to create a command that moves files or marked files to their parent directory (0:08). Here's a breakdown of the video's content: • Demonstration of manual file movement in Emacs Dired (1:02): The speaker first demonstrates the manual process of moving files in Emacs's Dired mode, which involves splitting windows, navigating directories, marking files, and using the capital R key to move them (1:02-2:08). • He emphasizes the desire to automate this process with a single command (2:12). • Introduction to Dired and File Managers (3:28): The speaker explains Dired as Emacs's directory editor, which is essentially a file manager. • He compares it to Windows File Explorer, Mac Finder, and various Linux file managers (3:28-4:32). • Getting a list of marked files (5:02): The first step in coding the command is to get a list of files that are currently marked in Dired. • If no files are marked, the file under the cursor is considered the "current file" (5:02-6:10). • The dired-get-marked-files command is used for this purpose (7:21). • Finding the parent directory (9:25): The speaker then looks for the function to find the parent directory of a given file path. • He refers to his own Emacs Lisp tutorial for this (9:32-11:58). • He identifies file-name-directory as the function to get the directory of a file and later introduces file-name-parent-directory for obtaining the parent directory specifically (52:22). • Renaming/Moving files with rename-file (12:50): The rename-file command is introduced as the way to move or rename files, following Unix conventions (13:13). • Discussion on car and cdr in Lisp (15:22): A significant portion of the video is dedicated to explaining car and cdr (pronounced "car" and "carder" by the speaker) in Lisp. • Cons Cells: He explains that Lisp lists are fundamentally built from "cons cells," which are pairs of two things (17:45). • car refers to the first part of a cons cell, and cdr refers to the second part (20:16-20:58). • Nesting for Lists: Lists are formed by nesting these cons cells (21:56). • Historical Context: The speaker provides historical context, explaining that this design originated from early Lisp machines that had hardware optimized for these two-part cells (23:41). • Modern Alternatives: He advises against using the nested car and cdr functions (like cadr or cddar) for accessing elements in a list, calling them "idiotic" and "silly" (28:18-33:11). • Instead, he recommends using higher-level functions like nth for direct access (33:37) and push and pop for stack-like operations (36:56). • List Traversal and Efficiency: He highlights that functions like length for lists are inefficient because they have to traverse each element, which is a nature of Lisp's linked list implementation (38:55). • Completing the file movement command (42:30): The speaker proceeds to finalize the Emacs Lisp command, using mapc to apply the rename-file function to each selected file, concatenating the parent directory with the file's name (55:57). • Testing the command (56:30): The command is successfully tested by moving a file to its parent directory and then moving it back (56:30-58:06). • Refinement and Future Improvements (58:11): The speaker notes that the command could be further refined by adding error checking for root directories and printing messages about the move (58:11). • He also discusses simplifying the code by removing unnecessary variables (59:23) and functional programing technique to not use any variable or constant. Notes at http ://xahlee .info/talk_show/xah_talk_show_ep712.html Copy the link, remove spaces, paste the link in browser tab. Google Chrome and Firefox browsers censor websites by auto adding s in http and says the site Secure Connection Failed. Use Brave Browser or Safari.


Tracks in this Playlist

✅ Progress Tracking

Automatically track which videos you have watched. Your completion status is updated at a glance, preventing you from re-watching episodes by mistake.

⏯️ Resume Playback

Never lose your spot. Our custom player remembers your exact video and timestamp, allowing you to dive right back in seamlessly.

📱 Cross-Device Sync

Sync your playlist states, watched progress, and premium preferences across your desktop, laptop, tablet, and mobile phone automatically.

Start Organizing Your YouTube Playlists

Simply paste any YouTube playlist URL or channel link in the application search bar to immediately generate a custom, sorted, and progress-tracked workspace. No registration required to start.

Explore Playlist Guides & How-Tos