mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Support \ for line continuation in the configuration file, from Julius
Plenz.
This commit is contained in:
		
							
								
								
									
										35
									
								
								cfg.c
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								cfg.c
									
									
									
									
									
								
							@@ -92,22 +92,37 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
 | 
				
			|||||||
	retval = 0;
 | 
						retval = 0;
 | 
				
			||||||
	while ((buf = fgetln(f, &len))) {
 | 
						while ((buf = fgetln(f, &len))) {
 | 
				
			||||||
		if (buf[len - 1] == '\n')
 | 
							if (buf[len - 1] == '\n')
 | 
				
			||||||
			buf[len - 1] = '\0';
 | 
								len--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (line != NULL)
 | 
				
			||||||
 | 
								line = xrealloc(line, 1, strlen(line) + len + 1);
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
			line = xrealloc(line, 1, len + 1);
 | 
								line = xmalloc(len + 1);
 | 
				
			||||||
			memcpy(line, buf, len);
 | 
								*line = '\0';
 | 
				
			||||||
			line[len] = '\0';
 | 
					 | 
				
			||||||
			buf = line;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* Append buffer to line. strncat will terminate. */
 | 
				
			||||||
 | 
							strncat(line, buf, len);
 | 
				
			||||||
		n++;
 | 
							n++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* Continuation: get next line? */
 | 
				
			||||||
 | 
							len = strlen(line);
 | 
				
			||||||
 | 
							if (len > 0 && line[len - 1] == '\\') {
 | 
				
			||||||
 | 
								line[len - 1] = '\0';
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							buf = line;
 | 
				
			||||||
 | 
							line = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
 | 
							if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
 | 
				
			||||||
 | 
								xfree(buf);
 | 
				
			||||||
			if (cause == NULL)
 | 
								if (cause == NULL)
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
 | 
								cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
 | 
				
			||||||
			xfree(cause);
 | 
								xfree(cause);
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							} else
 | 
				
			||||||
 | 
								xfree(buf);
 | 
				
			||||||
		if (cmdlist == NULL)
 | 
							if (cmdlist == NULL)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		cfg_cause = NULL;
 | 
							cfg_cause = NULL;
 | 
				
			||||||
@@ -131,12 +146,16 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
 | 
				
			|||||||
			retval = 1;
 | 
								retval = 1;
 | 
				
			||||||
		cmd_list_free(cmdlist);
 | 
							cmd_list_free(cmdlist);
 | 
				
			||||||
		if (cfg_cause != NULL) {
 | 
							if (cfg_cause != NULL) {
 | 
				
			||||||
			cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
 | 
								cfg_add_cause(
 | 
				
			||||||
 | 
								    causes, "%s: %d: %s", path, n, cfg_cause);
 | 
				
			||||||
			xfree(cfg_cause);
 | 
								xfree(cfg_cause);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (line != NULL)
 | 
						if (line != NULL) {
 | 
				
			||||||
 | 
							cfg_add_cause(causes,
 | 
				
			||||||
 | 
							    "%s: %d: line continuation at end of file", path, n);
 | 
				
			||||||
		xfree(line);
 | 
							xfree(line);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	fclose(f);
 | 
						fclose(f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return (retval);
 | 
						return (retval);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								tmux.1
									
									
									
									
									
								
							@@ -491,7 +491,8 @@ $ tmux bind-key F1 set-window-option force-width 81
 | 
				
			|||||||
Multiple commands may be specified together as part of a
 | 
					Multiple commands may be specified together as part of a
 | 
				
			||||||
.Em command sequence .
 | 
					.Em command sequence .
 | 
				
			||||||
Each command should be separated by spaces and a semicolon;
 | 
					Each command should be separated by spaces and a semicolon;
 | 
				
			||||||
commands are executed sequentially from left to right.
 | 
					commands are executed sequentially from left to right and
 | 
				
			||||||
 | 
					lines ending with a backslash continue on to the next line.
 | 
				
			||||||
A literal semicolon may be included by escaping it with a backslash (for
 | 
					A literal semicolon may be included by escaping it with a backslash (for
 | 
				
			||||||
example, when specifying a command sequence to
 | 
					example, when specifying a command sequence to
 | 
				
			||||||
.Ic bind-key ) .
 | 
					.Ic bind-key ) .
 | 
				
			||||||
@@ -507,6 +508,9 @@ rename-session -tfirst newname
 | 
				
			|||||||
set-window-option -t:0 monitor-activity on
 | 
					set-window-option -t:0 monitor-activity on
 | 
				
			||||||
 | 
					
 | 
				
			||||||
new-window ; split-window -d
 | 
					new-window ; split-window -d
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bind-key R source-file ~/.tmux.conf \e; \e
 | 
				
			||||||
 | 
						display-message "source-file done"
 | 
				
			||||||
.Ed
 | 
					.Ed
 | 
				
			||||||
.Pp
 | 
					.Pp
 | 
				
			||||||
Or from
 | 
					Or from
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user